Skip to content

Commit 23f9e9a

Browse files
committed
Finish 3.1.0
2 parents 6bceabb + 4bd92f7 commit 23f9e9a

40 files changed

+327
-229
lines changed

.travis.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
language: ruby
2-
bundler_args: --without debug
32
script: "bundle exec rspec spec"
4-
before_install:
5-
- 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)'
6-
- 'gem update bundler --conservative'
73
env:
84
- CI=true
95
rvm:
10-
- 2.2.2
11-
- 2.3
126
- 2.4
137
- 2.5
148
- 2.6
9+
- 2.7
1510
- jruby
16-
- rbx-3
1711
cache: bundler
1812
sudo: false
1913
matrix:
2014
allow_failures:
2115
- rvm: jruby
22-
- rvm: rbx-3
2316
dist: trusty

Gemfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ group :develop do
1010
gem "rdf-vocab", git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop"
1111
gem "rdf-xsd", git: "https://github.com/ruby-rdf/rdf-xsd", branch: "develop"
1212

13+
gem "ebnf", git: "https://github.com/gkellogg/ebnf", branch: "develop"
14+
gem "sxp", git: "https://github.com/dryruby/sxp", branch: "develop"
15+
1316
gem 'rest-client-components'
1417
gem 'benchmark-ips'
1518

@@ -29,6 +32,6 @@ group :test do
2932
gem "rake"
3033
gem "equivalent-xml"
3134
gem 'fasterer'
32-
gem 'simplecov', require: false, platform: :mri
33-
gem 'coveralls', require: false, platform: :mri
35+
gem 'simplecov', platforms: :mri
36+
gem 'coveralls', '~> 0.8', platforms: :mri
3437
end

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ This is a pure-Ruby library for working with [Resource Description Framework
2929
not modify any of Ruby's core classes or standard library.
3030
* Based entirely on Ruby's autoloading, meaning that you can generally make
3131
use of any one part of the library without needing to load up the rest.
32-
* Compatible with Ruby Ruby >= 2.2.2, Rubinius and JRuby 9.0+.
32+
* Compatible with Ruby Ruby >= 2.4, Rubinius and JRuby 9.0+.
33+
* Note, changes in mapping hashes to keyword arguments for Ruby 2.7+ may require that arguments be passed more explicitly, especially when the first argument is a Hash and there are optional keyword arguments. In this case, Hash argument may need to be explicitly included within `{}` and the optional keyword arguments may need to be specified using `**{}` if there are no keyword arguments.
3334
* Performs auto-detection of input to select appropriate Reader class if one
3435
cannot be determined from file characteristics.
3536

@@ -189,7 +190,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
189190
FOAF.name => :name,
190191
FOAF.mbox => :email,
191192
}
192-
})
193+
}, **{})
193194

194195
query.execute(graph) do |solution|
195196
puts "name=#{solution.name} email=#{solution.email}"

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.13
1+
3.1.0

examples/query_bench.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
require 'rdf/ntriples'
77
graph = RDF::Graph.load("etc/doap.nt")
88

9-
puts graph.query(predicate: RDF::Vocab::FOAF.name).is_a?(RDF::Queryable)
9+
puts graph.query({predicate: RDF::Vocab::FOAF.name}).is_a?(RDF::Queryable)
1010

1111
Benchmark.ips do |x|
1212
x.config(:time => 10, :warmup => 5)
13-
x.report('query_pattern') { graph.query(predicate: RDF::Vocab::FOAF.name) {} }
13+
x.report('query_pattern') { graph.query({predicate: RDF::Vocab::FOAF.name}) {} }
1414
end

lib/rdf.rb

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,37 +79,44 @@ def self.const_missing(constant)
7979
#
8080
# @param (see RDF::Resource#initialize)
8181
# @return [RDF::Resource]
82-
def self.Resource(*args, &block)
83-
Resource.new(*args, &block)
82+
def self.Resource(*args)
83+
Resource.new(*args)
8484
end
8585

8686
##
8787
# Alias for `RDF::Node.new`.
8888
#
8989
# @param (see RDF::Node#initialize)
9090
# @return [RDF::Node]
91-
def self.Node(*args, &block)
92-
Node.new(*args, &block)
91+
def self.Node(*args)
92+
Node.new(*args)
9393
end
9494

9595
##
9696
# Cast to a URI. If already a URI, return the passed argument.
9797
#
9898
# @param (see RDF::URI#initialize)
9999
# @return [RDF::URI]
100-
def self.URI(uri, *args, &block)
101-
uri.respond_to?(:to_uri) ? uri.to_uri : URI.new(uri, *args, &block)
100+
def self.URI(*args)
101+
if args.first.respond_to?(:to_uri)
102+
args.first.to_uri
103+
elsif args.first.is_a?(Hash)
104+
URI.new(**args.first)
105+
else
106+
opts = args.last.is_a?(Hash) ? args.pop : {}
107+
URI.new(*args, **opts)
108+
end
102109
end
103110

104111
##
105112
# Alias for `RDF::Literal.new`.
106113
#
107114
# @param (see RDF::Literal#initialize)
108115
# @return [RDF::Literal]
109-
def self.Literal(literal, *args, &block)
116+
def self.Literal(literal, **options)
110117
case literal
111118
when RDF::Literal then literal
112-
else Literal.new(literal, *args, &block)
119+
else Literal.new(literal, **options)
113120
end
114121
end
115122

@@ -119,7 +126,7 @@ def self.Literal(literal, *args, &block)
119126
# @param (see RDF::Graph#initialize)
120127
# @return [RDF::Graph]
121128
def self.Graph(**options, &block)
122-
Graph.new(options, &block)
129+
Graph.new(**options, &block)
123130
end
124131

125132
##
@@ -171,11 +178,11 @@ def self.List(*args)
171178
# @option options [RDF::Resource] :graph_name (nil)
172179
# @return [RDF::Statement]
173180
#
174-
def self.Statement(*args)
175-
if args.empty?
181+
def self.Statement(*args, **options)
182+
if args.empty? && options.empty?
176183
RDF[:Statement]
177184
else
178-
Statement.new(*args)
185+
Statement.new(*args, **options)
179186
end
180187
end
181188

lib/rdf/changeset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Changeset
4242
# @yieldparam [RDF::Changeset] changes
4343
# @return [void]
4444
def self.apply(mutable, **options, &block)
45-
self.new(&block).apply(mutable, options)
45+
self.new(&block).apply(mutable, **options)
4646
end
4747

4848
##

lib/rdf/cli.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def to_hash
175175
unless repository.count > 0
176176
start = Time.new
177177
count = 0
178-
self.parse(argv, opts) do |reader|
178+
self.parse(argv, **opts) do |reader|
179179
reader.each_statement do |statement|
180180
count += 1
181181
end
@@ -240,7 +240,7 @@ def to_hash
240240
out = opts[:output]
241241
opts = opts.merge(prefixes: {})
242242
writer_opts = opts.merge(standard_prefixes: true)
243-
writer_class.new(out, writer_opts) do |writer|
243+
writer_class.new(out, **writer_opts) do |writer|
244244
writer << repository
245245
end
246246
end
@@ -501,7 +501,7 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
501501
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
502502
start = Time.new
503503
count = 0
504-
self.parse(args, options) do |reader|
504+
self.parse(args, **options) do |reader|
505505
@repository << reader
506506
end
507507
secs = Time.new - start
@@ -575,7 +575,7 @@ def self.load_commands
575575
RDF::Format.each do |format|
576576
format.cli_commands.each do |command, options|
577577
options = {lambda: options} unless options.is_a?(Hash)
578-
add_command(command, options)
578+
add_command(command, **options)
579579
end
580580
end
581581
@commands_loaded = true
@@ -637,13 +637,13 @@ def self.parse(files, evaluate: nil, format: nil, encoding: Encoding::UTF_8, **o
637637
r = RDF::Reader.for(format|| {sample: sample})
638638
raise ArgumentError, "Unknown format for evaluated input" unless r
639639
(@readers ||= []) << r
640-
r.new(input, options) do |reader|
640+
r.new(input, **options) do |reader|
641641
yield(reader)
642642
end
643643
else
644644
options[:format] = format if format
645645
files.each do |file|
646-
RDF::Reader.open(file, options) do |reader|
646+
RDF::Reader.open(file, **options) do |reader|
647647
(@readers ||= []) << reader.class.to_s
648648
yield(reader)
649649
end

lib/rdf/format.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def self.each(file_name: nil,
122122
sample = case sample
123123
when Proc then sample.call.to_s
124124
else sample.dup.to_s
125-
end.force_encoding(Encoding::ASCII_8BIT)
125+
end.dup.force_encoding(Encoding::ASCII_8BIT)
126126
# Given a sample, perform format detection across the appropriate formats, choosing the last that matches
127127
# Return last format that has a positive detection
128128
formats = formats.select {|f| f.detect(sample)}
@@ -145,10 +145,10 @@ def self.each(file_name: nil,
145145
# @param [String, RDF::URI] filename
146146
# @return [Class]
147147
#
148-
# @overload for(**options)
148+
# @overload for(options)
149149
# Finds an RDF serialization format class based on various options.
150150
#
151-
# @param [Hash{Symbol => Object}] options
151+
# @param [Hash{Symbol => Object}] options ({})
152152
# @option options [String, #to_s] :file_name (nil)
153153
# @option options [Symbol, #to_sym] :file_extension (nil)
154154
# @option options [String, #to_s] :content_type (nil)
@@ -164,27 +164,34 @@ def self.each(file_name: nil,
164164
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
165165
#
166166
# @return [Class]
167-
def self.for(*args, **options, &block)
167+
def self.for(*arg, &block)
168+
case arg.length
169+
when 0 then arg = nil
170+
when 1 then arg = arg.first
171+
else
172+
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
173+
end
174+
175+
options = arg.is_a?(Hash) ? arg : {}
168176
options = {sample: block}.merge(options) if block_given?
169-
formats = case args.first
177+
formats = case arg
170178
when String, RDF::URI
171179
# Find a format based on the file name
172-
self.each(file_name: args.first, **options).to_a
180+
self.each(file_name: arg, **options).to_a
173181
when Symbol
174182
# Try to find a match based on the full class name
175183
# We want this to work even if autoloading fails
176-
fmt = args.first
177-
classes = self.each(options).select {|f| f.symbols.include?(fmt)}
184+
classes = self.each(**options).select {|f| f.symbols.include?(arg)}
178185
if classes.empty?
179-
classes = case fmt
186+
classes = case arg
180187
when :ntriples then [RDF::NTriples::Format]
181188
when :nquads then [RDF::NQuads::Format]
182189
else []
183190
end
184191
end
185192
classes
186193
else
187-
self.each(options.merge(all_if_none: false)).to_a
194+
self.each(**options.merge(all_if_none: false)).to_a
188195
end
189196

190197
# Return the last detected format

lib/rdf/mixin/enumerable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def has_triple?(triple)
220220
def each_triple
221221
if block_given?
222222
each_statement do |statement|
223-
yield *statement.to_triple
223+
yield(*statement.to_triple)
224224
end
225225
end
226226
enum_triple
@@ -282,7 +282,7 @@ def has_quad?(quad)
282282
def each_quad
283283
if block_given?
284284
each_statement do |statement|
285-
yield *statement.to_quad
285+
yield(*statement.to_quad)
286286
end
287287
end
288288
enum_quad

lib/rdf/mixin/mutable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def immutable?
3737
# @option options [RDF::Resource] :graph_name
3838
# Set set graph name of each loaded statement
3939
# @return [void]
40-
def load(url, graph_name: nil, **options)
40+
def load(url, graph_name: nil, **options)
4141
raise TypeError.new("#{self} is immutable") if immutable?
4242

43-
Reader.open(url, {base_uri: url}.merge(options)) do |reader|
43+
Reader.open(url, base_uri: url, **options) do |reader|
4444
if graph_name
4545
statements = []
4646
reader.each_statement do |statement|

lib/rdf/mixin/queryable.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Queryable
1919
#
2020
# @example Querying for statements having a given predicate
2121
# queryable.query([nil, RDF::Vocab::DOAP.developer, nil])
22-
# queryable.query(predicate: RDF::Vocab::DOAP.developer) do |statement|
22+
# queryable.query({predicate: RDF::Vocab::DOAP.developer}) do |statement|
2323
# puts statement.inspect
2424
# end
2525
#
@@ -50,7 +50,7 @@ def query(pattern, **options, &block)
5050
solutions = RDF::Query::Solutions.new
5151
block = lambda {|solution| solutions << solution} unless block_given?
5252
before_query(pattern) if respond_to?(:before_query)
53-
query_execute(pattern, options, &block)
53+
query_execute(pattern, **options, &block)
5454
after_query(pattern) if respond_to?(:after_query)
5555
# Returns the solutions, not an enumerator
5656
solutions
@@ -85,7 +85,7 @@ def query(pattern, **options, &block)
8585

8686
# Otherwise, we delegate to `#query_pattern`:
8787
else # pattern.variable?
88-
query_pattern(pattern, options, &block)
88+
query_pattern(pattern, **options, &block)
8989
end
9090
after_query(pattern) if respond_to?(:after_query)
9191
enum
@@ -116,7 +116,7 @@ def query_execute(query, **options, &block)
116116
# query execution by breaking down the query into its constituent
117117
# triple patterns and invoking `RDF::Query::Pattern#execute` on each
118118
# pattern.
119-
query.execute(self, options, &block)
119+
query.execute(self, **options, &block)
120120
end
121121
protected :query_execute
122122

lib/rdf/model/graph.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def anonymous?
211211
# @return [Integer]
212212
# @see RDF::Enumerable#count
213213
def count
214-
@data.query(graph_name: graph_name || false).count
214+
@data.query({graph_name: graph_name || false}).count
215215
end
216216

217217
##
@@ -237,7 +237,7 @@ def has_statement?(statement)
237237
# @see RDF::Enumerable#each_statement
238238
def each(&block)
239239
if @data.respond_to?(:query)
240-
@data.query(graph_name: graph_name || false, &block)
240+
@data.query({graph_name: graph_name || false}, &block)
241241
elsif @data.respond_to?(:each)
242242
@data.each(&block)
243243
else

0 commit comments

Comments
 (0)