Skip to content

Commit

Permalink
Finish 2.2.0-rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 31, 2016
2 parents 5eca224 + 7c14f07 commit 5f034de
Show file tree
Hide file tree
Showing 48 changed files with 635 additions and 378 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
rvm:
- 2.2.6
- 2.3.3
- 2.4.0
- jruby
- rbx
cache: bundler
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
2.2.0-rc1
4 changes: 2 additions & 2 deletions lib/rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def self.List(*args)
# @overload Statement()
# @return [RDF::URI] returns the IRI for `rdf:Statement`
#
# @overload Statement(options = {})
# @overload Statement(**options)
# @param [Hash{Symbol => Object}] options
# @option options [RDF::Resource] :subject (nil)
# @option options [RDF::URI] :predicate (nil)
Expand All @@ -165,7 +165,7 @@ def self.List(*args)
# Note, a graph_name MUST be an IRI or BNode.
# @return [RDF::Statement]
#
# @overload Statement(subject, predicate, object, options = {})
# @overload Statement(subject, predicate, object, **options)
# @param [RDF::Resource] subject
# @param [RDF::URI] predicate
# @param [RDF::Term] object
Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Changeset
# @yield [changes]
# @yieldparam [RDF::Changeset] changes
# @return [void]
def self.apply(mutable, options = {}, &block)
def self.apply(mutable, **options, &block)
self.new(&block).apply(mutable, options)
end

Expand Down Expand Up @@ -106,7 +106,7 @@ def readable?
# @param [RDF::Mutable] mutable
# @param [Hash{Symbol => Object}] options
# @return [void]
def apply(mutable, options = {})
def apply(mutable, **options)
mutable.apply_changeset(self)
end

Expand Down
30 changes: 18 additions & 12 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,24 @@ def self.usage(options, banner: nil)
# Execute one or more commands, parsing input as necessary
#
# @param [Array<String>] args
# @param [IO] output
# @param [Hash{Symbol => Object}] options
# @return [Boolean]
def self.exec(args, options = {})
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if out.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
def self.exec(args, output: $stdout, option_parser: self.options, **options)
output.set_encoding(Encoding::UTF_8) if output.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
cmds, args = args.partition {|e| commands.include?(e.to_s)}

if cmds.empty?
usage(options.fetch(:option_parser, self.options))
usage(option_parser)
abort "No command given"
end

if cmds.first == 'help'
on_cmd = cmds[1]
if on_cmd && COMMANDS.fetch(on_cmd.to_sym, {})[:help]
usage(options.fetch(:option_parser, self.options), banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
usage(option_parser, banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
else
usage(options.fetch(:option_parser, self.options))
usage(option_parser)
end
return
end
Expand All @@ -374,7 +375,7 @@ def self.exec(args, options = {})

# Run each command in sequence
cmds.each do |command|
COMMANDS[command.to_sym][:lambda].call(args, options)
COMMANDS[command.to_sym][:lambda].call(args, output: output, **options)
end
rescue ArgumentError => e
abort e.message
Expand Down Expand Up @@ -409,7 +410,7 @@ def self.commands
# @yieldparam [Array<String>] argv
# @yieldparam [Hash] opts
# @yieldreturn [void]
def self.add_command(command, options = {}, &block)
def self.add_command(command, **options, &block)
options[:lambda] = block if block_given?
COMMANDS[command.to_sym] ||= options
end
Expand All @@ -431,20 +432,25 @@ def self.formats(reader: false, writer: false)
# yielding a reader
#
# @param [Array<String>] files
# @param [String] evaluate from command-line, rather than referenced file
# @param [Symbol] format (:ntriples) Reader symbol for finding reader
# @param [Encoding] encoding set on the input
# @param [Hash{Symbol => Object}] options sent to reader
# @yield [reader]
# @yieldparam [RDF::Reader]
# @return [nil]
def self.parse(files, options = {}, &block)
def self.parse(files, evaluate: nil, format: :ntriples, encoding: Encoding::UTF_8, **options, &block)
if files.empty?
# If files are empty, either use options[:execute]
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : $stdin
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
r = RDF::Reader.for(options[:format] || :ntriples)
input = evaluate ? StringIO.new(evaluate) : $stdin
input.set_encoding(encoding)
r = RDF::Reader.for(format)
(@readers ||= []) << r
r.new(input, options) do |reader|
yield(reader)
end
else
options[:format] = format if format
files.each do |file|
RDF::Reader.open(file, options) do |reader|
(@readers ||= []) << reader.class.to_s
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.each(&block)
# @param [String, RDF::URI] filename
# @return [Class]
#
# @overload for(options = {})
# @overload for(**options)
# Finds an RDF serialization format class based on various options.
#
# @param [Hash{Symbol => Object}] options
Expand Down
29 changes: 22 additions & 7 deletions lib/rdf/mixin/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def validate!
# @return [Array<RDF::Statement>]
# @see #each_statement
# @see #enum_statement
def statements(options = {})
def statements(**options)
Array(enum_statement)
end

Expand Down Expand Up @@ -184,7 +184,7 @@ def enum_statement
# @return [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>]
# @see #each_triple
# @see #enum_triple
def triples(options = {})
def triples(**options)
enum_statement.map(&:to_triple) # TODO: optimize
end

Expand Down Expand Up @@ -245,7 +245,7 @@ def enum_triple
# @return [Array<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>]
# @see #each_quad
# @see #enum_quad
def quads(options = {})
def quads(**options)
enum_statement.map(&:to_quad) # TODO: optimize
end

Expand Down Expand Up @@ -711,7 +711,7 @@ def to_set
# `{subject => {predicate => [*objects]}}`.
#
# @return [Hash]
def to_hash
def to_h
result = {}
each_statement do |statement|
result[statement.subject] ||= {}
Expand All @@ -738,21 +738,36 @@ def to_hash
# @see RDF::Writer.dump
# @raise [RDF::WriterError] if no writer found
# @since 0.2.0
def dump(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
def dump(*args, **options)
writer = RDF::Writer.for(*args)
raise RDF::WriterError, "No writer found using #{args.inspect}" unless writer
writer.dump(self, nil, options)
writer.dump(self, nil, **options)
end

protected

##
# @overload #to_hash
# Returns all RDF object terms indexed by their subject and predicate
# terms.
#
# The return value is a `Hash` instance that has the structure:
# `{subject => {predicate => [*objects]}}`.
#
# @return [Hash]
# @deprecated Use {#to_h} instead.
# @overload #to_writer
# Implements #to_writer for each available instance of {RDF::Writer},
# based on the writer symbol.
#
# @return [String]
# @see {RDF::Writer.sym}
def method_missing(meth, *args)
case meth
when :to_hash
warn "[DEPRECATION] Enumerable#to_hash is deprecated, use Enumerable#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
return self.to_h
end
writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_"
if writer
writer.buffer(standard_prefixes: true) {|w| w << self}
Expand Down
44 changes: 40 additions & 4 deletions lib/rdf/mixin/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@ class Enumerator < ::Enumerator
include Queryable
include Enumerable

# Make sure returned arrays are also queryable
##
# @return [Array]
# @note Make sure returned arrays are also queryable
def to_a
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
end
alias_method :to_ary, :to_a

protected

##
# @overload #to_ary
# @see #to_a
# @deprecated use {#to_a} instead
def method_missing(name, *args)
if name == :to_ary
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
"#{self.class}#to_a instead. Called from " \
"#{Gem.location_of_caller.join(':')}"
to_a
else
super
end
end
end
end

Expand All @@ -28,11 +46,29 @@ class Enumerator < ::Enumerator
include Queryable
include Enumerable

# Make sure returned arrays are also queryable
##
# @return [Array]
# @note Make sure returned arrays are also queryable
def to_a
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
end
alias_method :to_ary, :to_a

protected

##
# @overload #to_ary
# @see #to_a
# @deprecated use {#to_a} instead
def method_missing(name, *args)
if name == :to_ary
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
"#{self.class}#to_a instead. Called from " \
"#{Gem.location_of_caller.join(':')}"
self.to_a
else
super
end
end
end
end
end
6 changes: 3 additions & 3 deletions lib/rdf/mixin/queryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module Queryable
# Returns an enumerable of statements (may be an enumerator) or query solutions, if passed an {RDF::Query}
# @see RDF::Queryable#query_pattern
# @note Since 2.0, this may return an Enumerable or an Enumerator in addition to Solutions
def query(pattern, options = {}, &block)
def query(pattern, **options, &block)
raise TypeError, "#{self} is not readable" if respond_to?(:readable?) && !readable?

case pattern
Expand Down Expand Up @@ -111,7 +111,7 @@ def query(pattern, options = {}, &block)
# @see RDF::Queryable#query
# @see RDF::Query#execute
# @since 0.3.0
def query_execute(query, options = {}, &block)
def query_execute(query, **options, &block)
# By default, we let RDF.rb's built-in `RDF::Query#execute` handle BGP
# query execution by breaking down the query into its constituent
# triple patterns and invoking `RDF::Query::Pattern#execute` on each
Expand Down Expand Up @@ -139,7 +139,7 @@ def query_execute(query, options = {}, &block)
# @see RDF::Queryable#query
# @see RDF::Query::Pattern#execute
# @since 0.2.0
def query_pattern(pattern, options = {}, &block)
def query_pattern(pattern, **options, &block)
# By default, we let Ruby's built-in `Enumerable#grep` handle the
# matching of statements by iterating over all statements and calling
# `RDF::Query::Pattern#===` on each statement.
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/model/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def supports?(feature)
##
# Implements basic query pattern matching over the Dataset, with handling
# for a default graph.
def query_pattern(pattern, options = {}, &block)
def query_pattern(pattern, **options, &block)
return super unless pattern.graph_name == DEFAULT_GRAPH

if block_given?
Expand Down
8 changes: 4 additions & 4 deletions lib/rdf/model/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def self.load(url, graph_name: nil, **options, &block)
end

##
# @param [RDF::Resource] graph_name
# @param [RDF::Resource] graph_name
# The graph_name from the associated {RDF::Queryable} associated
# with this graph as provided with the `:data` option
# (only for {RDF::Queryable} instances supporting
# named graphs).
# @param [RDF::Queryable] :data (RDF::Repository.new)
# @param [RDF::Queryable] data (RDF::Repository.new)
# Storage behind this graph.
#
# @raise [ArgumentError] if a `data` does not support named graphs.
Expand Down Expand Up @@ -273,7 +273,7 @@ def ==(other)
##
# @private
# @see RDF::Queryable#query_pattern
def query_pattern(pattern, options = {}, &block)
def query_pattern(pattern, **options, &block)
pattern = pattern.dup
pattern.graph_name = graph_name || false
@data.query(pattern, &block)
Expand All @@ -294,7 +294,7 @@ def insert_statement(statement)
def insert_statements(statements)
enum = Enumerable::Enumerator.new do |yielder|

statements.send(method = statements.respond_to?(:each_statement) ? :each_statement : :each) do |s|
statements.send(statements.respond_to?(:each_statement) ? :each_statement : :each) do |s|
s = s.dup
s.graph_name = graph_name
yielder << s
Expand Down

0 comments on commit 5f034de

Please sign in to comment.