Skip to content

Commit 5f034de

Browse files
committed
Finish 2.2.0-rc1
2 parents 5eca224 + 7c14f07 commit 5f034de

48 files changed

Lines changed: 635 additions & 378 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ env:
66
rvm:
77
- 2.2.6
88
- 2.3.3
9+
- 2.4.0
910
- jruby
1011
- rbx
1112
cache: bundler

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.1
1+
2.2.0-rc1

lib/rdf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def self.List(*args)
156156
# @overload Statement()
157157
# @return [RDF::URI] returns the IRI for `rdf:Statement`
158158
#
159-
# @overload Statement(options = {})
159+
# @overload Statement(**options)
160160
# @param [Hash{Symbol => Object}] options
161161
# @option options [RDF::Resource] :subject (nil)
162162
# @option options [RDF::URI] :predicate (nil)
@@ -165,7 +165,7 @@ def self.List(*args)
165165
# Note, a graph_name MUST be an IRI or BNode.
166166
# @return [RDF::Statement]
167167
#
168-
# @overload Statement(subject, predicate, object, options = {})
168+
# @overload Statement(subject, predicate, object, **options)
169169
# @param [RDF::Resource] subject
170170
# @param [RDF::URI] predicate
171171
# @param [RDF::Term] object

lib/rdf/changeset.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Changeset
4141
# @yield [changes]
4242
# @yieldparam [RDF::Changeset] changes
4343
# @return [void]
44-
def self.apply(mutable, options = {}, &block)
44+
def self.apply(mutable, **options, &block)
4545
self.new(&block).apply(mutable, options)
4646
end
4747

@@ -106,7 +106,7 @@ def readable?
106106
# @param [RDF::Mutable] mutable
107107
# @param [Hash{Symbol => Object}] options
108108
# @return [void]
109-
def apply(mutable, options = {})
109+
def apply(mutable, **options)
110110
mutable.apply_changeset(self)
111111
end
112112

lib/rdf/cli.rb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -338,23 +338,24 @@ def self.usage(options, banner: nil)
338338
# Execute one or more commands, parsing input as necessary
339339
#
340340
# @param [Array<String>] args
341+
# @param [IO] output
342+
# @param [Hash{Symbol => Object}] options
341343
# @return [Boolean]
342-
def self.exec(args, options = {})
343-
out = options[:output] || $stdout
344-
out.set_encoding(Encoding::UTF_8) if out.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
344+
def self.exec(args, output: $stdout, option_parser: self.options, **options)
345+
output.set_encoding(Encoding::UTF_8) if output.respond_to?(:set_encoding) && RUBY_PLATFORM == "java"
345346
cmds, args = args.partition {|e| commands.include?(e.to_s)}
346347

347348
if cmds.empty?
348-
usage(options.fetch(:option_parser, self.options))
349+
usage(option_parser)
349350
abort "No command given"
350351
end
351352

352353
if cmds.first == 'help'
353354
on_cmd = cmds[1]
354355
if on_cmd && COMMANDS.fetch(on_cmd.to_sym, {})[:help]
355-
usage(options.fetch(:option_parser, self.options), banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
356+
usage(option_parser, banner: "Usage: #{self.basename.split('/').last} #{COMMANDS[on_cmd.to_sym][:help]}")
356357
else
357-
usage(options.fetch(:option_parser, self.options))
358+
usage(option_parser)
358359
end
359360
return
360361
end
@@ -374,7 +375,7 @@ def self.exec(args, options = {})
374375

375376
# Run each command in sequence
376377
cmds.each do |command|
377-
COMMANDS[command.to_sym][:lambda].call(args, options)
378+
COMMANDS[command.to_sym][:lambda].call(args, output: output, **options)
378379
end
379380
rescue ArgumentError => e
380381
abort e.message
@@ -409,7 +410,7 @@ def self.commands
409410
# @yieldparam [Array<String>] argv
410411
# @yieldparam [Hash] opts
411412
# @yieldreturn [void]
412-
def self.add_command(command, options = {}, &block)
413+
def self.add_command(command, **options, &block)
413414
options[:lambda] = block if block_given?
414415
COMMANDS[command.to_sym] ||= options
415416
end
@@ -431,20 +432,25 @@ def self.formats(reader: false, writer: false)
431432
# yielding a reader
432433
#
433434
# @param [Array<String>] files
435+
# @param [String] evaluate from command-line, rather than referenced file
436+
# @param [Symbol] format (:ntriples) Reader symbol for finding reader
437+
# @param [Encoding] encoding set on the input
438+
# @param [Hash{Symbol => Object}] options sent to reader
434439
# @yield [reader]
435440
# @yieldparam [RDF::Reader]
436441
# @return [nil]
437-
def self.parse(files, options = {}, &block)
442+
def self.parse(files, evaluate: nil, format: :ntriples, encoding: Encoding::UTF_8, **options, &block)
438443
if files.empty?
439444
# If files are empty, either use options[:execute]
440-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : $stdin
441-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
442-
r = RDF::Reader.for(options[:format] || :ntriples)
445+
input = evaluate ? StringIO.new(evaluate) : $stdin
446+
input.set_encoding(encoding)
447+
r = RDF::Reader.for(format)
443448
(@readers ||= []) << r
444449
r.new(input, options) do |reader|
445450
yield(reader)
446451
end
447452
else
453+
options[:format] = format if format
448454
files.each do |file|
449455
RDF::Reader.open(file, options) do |reader|
450456
(@readers ||= []) << reader.class.to_s

lib/rdf/format.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def self.each(&block)
7070
# @param [String, RDF::URI] filename
7171
# @return [Class]
7272
#
73-
# @overload for(options = {})
73+
# @overload for(**options)
7474
# Finds an RDF serialization format class based on various options.
7575
#
7676
# @param [Hash{Symbol => Object}] options

lib/rdf/mixin/enumerable.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def validate!
121121
# @return [Array<RDF::Statement>]
122122
# @see #each_statement
123123
# @see #enum_statement
124-
def statements(options = {})
124+
def statements(**options)
125125
Array(enum_statement)
126126
end
127127

@@ -184,7 +184,7 @@ def enum_statement
184184
# @return [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>]
185185
# @see #each_triple
186186
# @see #enum_triple
187-
def triples(options = {})
187+
def triples(**options)
188188
enum_statement.map(&:to_triple) # TODO: optimize
189189
end
190190

@@ -245,7 +245,7 @@ def enum_triple
245245
# @return [Array<Array(RDF::Resource, RDF::URI, RDF::Term, RDF::Resource)>]
246246
# @see #each_quad
247247
# @see #enum_quad
248-
def quads(options = {})
248+
def quads(**options)
249249
enum_statement.map(&:to_quad) # TODO: optimize
250250
end
251251

@@ -711,7 +711,7 @@ def to_set
711711
# `{subject => {predicate => [*objects]}}`.
712712
#
713713
# @return [Hash]
714-
def to_hash
714+
def to_h
715715
result = {}
716716
each_statement do |statement|
717717
result[statement.subject] ||= {}
@@ -738,21 +738,36 @@ def to_hash
738738
# @see RDF::Writer.dump
739739
# @raise [RDF::WriterError] if no writer found
740740
# @since 0.2.0
741-
def dump(*args)
742-
options = args.last.is_a?(Hash) ? args.pop : {}
741+
def dump(*args, **options)
743742
writer = RDF::Writer.for(*args)
744743
raise RDF::WriterError, "No writer found using #{args.inspect}" unless writer
745-
writer.dump(self, nil, options)
744+
writer.dump(self, nil, **options)
746745
end
747746

747+
protected
748+
748749
##
750+
# @overload #to_hash
751+
# Returns all RDF object terms indexed by their subject and predicate
752+
# terms.
753+
#
754+
# The return value is a `Hash` instance that has the structure:
755+
# `{subject => {predicate => [*objects]}}`.
756+
#
757+
# @return [Hash]
758+
# @deprecated Use {#to_h} instead.
749759
# @overload #to_writer
750760
# Implements #to_writer for each available instance of {RDF::Writer},
751761
# based on the writer symbol.
752762
#
753763
# @return [String]
754764
# @see {RDF::Writer.sym}
755765
def method_missing(meth, *args)
766+
case meth
767+
when :to_hash
768+
warn "[DEPRECATION] Enumerable#to_hash is deprecated, use Enumerable#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
769+
return self.to_h
770+
end
756771
writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_"
757772
if writer
758773
writer.buffer(standard_prefixes: true) {|w| w << self}

lib/rdf/mixin/enumerator.rb

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,29 @@ class Enumerator < ::Enumerator
77
include Queryable
88
include Enumerable
99

10-
# Make sure returned arrays are also queryable
10+
##
11+
# @return [Array]
12+
# @note Make sure returned arrays are also queryable
1113
def to_a
1214
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
1315
end
14-
alias_method :to_ary, :to_a
16+
17+
protected
18+
19+
##
20+
# @overload #to_ary
21+
# @see #to_a
22+
# @deprecated use {#to_a} instead
23+
def method_missing(name, *args)
24+
if name == :to_ary
25+
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
26+
"#{self.class}#to_a instead. Called from " \
27+
"#{Gem.location_of_caller.join(':')}"
28+
to_a
29+
else
30+
super
31+
end
32+
end
1533
end
1634
end
1735

@@ -28,11 +46,29 @@ class Enumerator < ::Enumerator
2846
include Queryable
2947
include Enumerable
3048

31-
# Make sure returned arrays are also queryable
49+
##
50+
# @return [Array]
51+
# @note Make sure returned arrays are also queryable
3252
def to_a
3353
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
3454
end
35-
alias_method :to_ary, :to_a
55+
56+
protected
57+
58+
##
59+
# @overload #to_ary
60+
# @see #to_a
61+
# @deprecated use {#to_a} instead
62+
def method_missing(name, *args)
63+
if name == :to_ary
64+
warn "[DEPRECATION] #{self.class}#to_ary is deprecated, use " \
65+
"#{self.class}#to_a instead. Called from " \
66+
"#{Gem.location_of_caller.join(':')}"
67+
self.to_a
68+
else
69+
super
70+
end
71+
end
3672
end
3773
end
3874
end

lib/rdf/mixin/queryable.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module Queryable
4141
# Returns an enumerable of statements (may be an enumerator) or query solutions, if passed an {RDF::Query}
4242
# @see RDF::Queryable#query_pattern
4343
# @note Since 2.0, this may return an Enumerable or an Enumerator in addition to Solutions
44-
def query(pattern, options = {}, &block)
44+
def query(pattern, **options, &block)
4545
raise TypeError, "#{self} is not readable" if respond_to?(:readable?) && !readable?
4646

4747
case pattern
@@ -111,7 +111,7 @@ def query(pattern, options = {}, &block)
111111
# @see RDF::Queryable#query
112112
# @see RDF::Query#execute
113113
# @since 0.3.0
114-
def query_execute(query, options = {}, &block)
114+
def query_execute(query, **options, &block)
115115
# By default, we let RDF.rb's built-in `RDF::Query#execute` handle BGP
116116
# query execution by breaking down the query into its constituent
117117
# triple patterns and invoking `RDF::Query::Pattern#execute` on each
@@ -139,7 +139,7 @@ def query_execute(query, options = {}, &block)
139139
# @see RDF::Queryable#query
140140
# @see RDF::Query::Pattern#execute
141141
# @since 0.2.0
142-
def query_pattern(pattern, options = {}, &block)
142+
def query_pattern(pattern, **options, &block)
143143
# By default, we let Ruby's built-in `Enumerable#grep` handle the
144144
# matching of statements by iterating over all statements and calling
145145
# `RDF::Query::Pattern#===` on each statement.

lib/rdf/model/dataset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def supports?(feature)
119119
##
120120
# Implements basic query pattern matching over the Dataset, with handling
121121
# for a default graph.
122-
def query_pattern(pattern, options = {}, &block)
122+
def query_pattern(pattern, **options, &block)
123123
return super unless pattern.graph_name == DEFAULT_GRAPH
124124

125125
if block_given?

0 commit comments

Comments
 (0)