Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
175 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,5 @@ Gemfile.lock | |
benchmark/ | ||
/.byebug_history | ||
/coverage/ | ||
\#*\# | ||
.\#* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.1.0 | ||
3.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
module RDF; module Util | ||
autoload :Aliasing, 'rdf/util/aliasing' | ||
autoload :Cache, 'rdf/util/cache' | ||
autoload :File, 'rdf/util/file' | ||
autoload :Logger, 'rdf/util/logger' | ||
autoload :UUID, 'rdf/util/uuid' | ||
autoload :Aliasing, 'rdf/util/aliasing' | ||
autoload :Cache, 'rdf/util/cache' | ||
autoload :File, 'rdf/util/file' | ||
autoload :Logger, 'rdf/util/logger' | ||
autoload :UUID, 'rdf/util/uuid' | ||
autoload :Coercions, 'rdf/util/coercions' | ||
end; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
module RDF | ||
module Util | ||
module Coercions | ||
# This is a provisional module intended to house input | ||
# coercions. Currently the only coercion is a statement | ||
# preprocessor that is used in e.g. {RDF::Writable#insert} and | ||
# {RDF::Mutable#delete}. | ||
|
||
protected | ||
|
||
## | ||
# Coerce an array of arguments into {RDF::Statement}, or | ||
# {RDF::Enumerable} and then yield to a block. Note that this | ||
# code was amalgamated from that which was sandwiched around | ||
# both {RDF::Writable#insert_statements} and | ||
# {RDF::Mutable#delete_statements}. The parameters `query` and | ||
# `constant` are therefore present to handle the conditions | ||
# where the statements contain wildcards and what to do about | ||
# them. | ||
# | ||
# @example | ||
# coerce_statements(statements) { |value| do_something(value) } | ||
# | ||
# @param statements [#map] The arbitrary-ish input to be manipulated | ||
# @param query [false, true] Whether to call `query` before the block | ||
# (as expected by {Mutable#delete_statements}) | ||
# @param constant [false, true] Whether to test if the statements | ||
# are constant (as expected by {Mutable#delete_statements}) | ||
# @yield [RDF::Statement, RDF::Enumerable] | ||
# @return statements | ||
def coerce_statements(statements, query: false, constant: false, &block) | ||
raise ArgumentError, 'expecting a block' unless block_given? | ||
|
||
statements = statements.map do |value| | ||
case | ||
when value.respond_to?(:each_statement) | ||
block.call(value) | ||
nil | ||
when (statement = Statement.from(value)) && | ||
(!constant || statement.constant?) | ||
statement | ||
when query | ||
# XXX note that this only makes sense when the module is include()d | ||
block.call(self.query(value)) | ||
nil | ||
else | ||
raise ArgumentError, "Not a valid statement: #{value.inspect}" | ||
end | ||
end.compact | ||
|
||
block.call(statements) unless statements.empty? | ||
|
||
# eh might as well return these | ||
statements | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters