Skip to content

Commit

Permalink
Finish 3.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 16, 2019
2 parents 6bceabb + 4bd92f7 commit 23f9e9a
Show file tree
Hide file tree
Showing 40 changed files with 327 additions and 229 deletions.
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install:
- 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)'
- 'gem update bundler --conservative'
env:
- CI=true
rvm:
- 2.2.2
- 2.3
- 2.4
- 2.5
- 2.6
- 2.7
- jruby
- rbx-3
cache: bundler
sudo: false
matrix:
allow_failures:
- rvm: jruby
- rvm: rbx-3
dist: trusty
7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ group :develop do
gem "rdf-vocab", git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop"
gem "rdf-xsd", git: "https://github.com/ruby-rdf/rdf-xsd", branch: "develop"

gem "ebnf", git: "https://github.com/gkellogg/ebnf", branch: "develop"
gem "sxp", git: "https://github.com/dryruby/sxp", branch: "develop"

gem 'rest-client-components'
gem 'benchmark-ips'

Expand All @@ -29,6 +32,6 @@ group :test do
gem "rake"
gem "equivalent-xml"
gem 'fasterer'
gem 'simplecov', require: false, platform: :mri
gem 'coveralls', require: false, platform: :mri
gem 'simplecov', platforms: :mri
gem 'coveralls', '~> 0.8', platforms: :mri
end
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ This is a pure-Ruby library for working with [Resource Description Framework
not modify any of Ruby's core classes or standard library.
* Based entirely on Ruby's autoloading, meaning that you can generally make
use of any one part of the library without needing to load up the rest.
* Compatible with Ruby Ruby >= 2.2.2, Rubinius and JRuby 9.0+.
* Compatible with Ruby Ruby >= 2.4, Rubinius and JRuby 9.0+.
* 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.
* Performs auto-detection of input to select appropriate Reader class if one
cannot be determined from file characteristics.

Expand Down Expand Up @@ -189,7 +190,7 @@ Note that no prefixes are loaded automatically, however they can be provided as
FOAF.name => :name,
FOAF.mbox => :email,
}
})
}, **{})

query.execute(graph) do |solution|
puts "name=#{solution.name} email=#{solution.email}"
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.13
3.1.0
4 changes: 2 additions & 2 deletions examples/query_bench.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
require 'rdf/ntriples'
graph = RDF::Graph.load("etc/doap.nt")

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

Benchmark.ips do |x|
x.config(:time => 10, :warmup => 5)
x.report('query_pattern') { graph.query(predicate: RDF::Vocab::FOAF.name) {} }
x.report('query_pattern') { graph.query({predicate: RDF::Vocab::FOAF.name}) {} }
end
31 changes: 19 additions & 12 deletions lib/rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,44 @@ def self.const_missing(constant)
#
# @param (see RDF::Resource#initialize)
# @return [RDF::Resource]
def self.Resource(*args, &block)
Resource.new(*args, &block)
def self.Resource(*args)
Resource.new(*args)
end

##
# Alias for `RDF::Node.new`.
#
# @param (see RDF::Node#initialize)
# @return [RDF::Node]
def self.Node(*args, &block)
Node.new(*args, &block)
def self.Node(*args)
Node.new(*args)
end

##
# Cast to a URI. If already a URI, return the passed argument.
#
# @param (see RDF::URI#initialize)
# @return [RDF::URI]
def self.URI(uri, *args, &block)
uri.respond_to?(:to_uri) ? uri.to_uri : URI.new(uri, *args, &block)
def self.URI(*args)
if args.first.respond_to?(:to_uri)
args.first.to_uri
elsif args.first.is_a?(Hash)
URI.new(**args.first)
else
opts = args.last.is_a?(Hash) ? args.pop : {}
URI.new(*args, **opts)
end
end

##
# Alias for `RDF::Literal.new`.
#
# @param (see RDF::Literal#initialize)
# @return [RDF::Literal]
def self.Literal(literal, *args, &block)
def self.Literal(literal, **options)
case literal
when RDF::Literal then literal
else Literal.new(literal, *args, &block)
else Literal.new(literal, **options)
end
end

Expand All @@ -119,7 +126,7 @@ def self.Literal(literal, *args, &block)
# @param (see RDF::Graph#initialize)
# @return [RDF::Graph]
def self.Graph(**options, &block)
Graph.new(options, &block)
Graph.new(**options, &block)
end

##
Expand Down Expand Up @@ -171,11 +178,11 @@ def self.List(*args)
# @option options [RDF::Resource] :graph_name (nil)
# @return [RDF::Statement]
#
def self.Statement(*args)
if args.empty?
def self.Statement(*args, **options)
if args.empty? && options.empty?
RDF[:Statement]
else
Statement.new(*args)
Statement.new(*args, **options)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/changeset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Changeset
# @yieldparam [RDF::Changeset] changes
# @return [void]
def self.apply(mutable, **options, &block)
self.new(&block).apply(mutable, options)
self.new(&block).apply(mutable, **options)
end

##
Expand Down
12 changes: 6 additions & 6 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def to_hash
unless repository.count > 0
start = Time.new
count = 0
self.parse(argv, opts) do |reader|
self.parse(argv, **opts) do |reader|
reader.each_statement do |statement|
count += 1
end
Expand Down Expand Up @@ -240,7 +240,7 @@ def to_hash
out = opts[:output]
opts = opts.merge(prefixes: {})
writer_opts = opts.merge(standard_prefixes: true)
writer_class.new(out, writer_opts) do |writer|
writer_class.new(out, **writer_opts) do |writer|
writer << repository
end
end
Expand Down Expand Up @@ -501,7 +501,7 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
start = Time.new
count = 0
self.parse(args, options) do |reader|
self.parse(args, **options) do |reader|
@repository << reader
end
secs = Time.new - start
Expand Down Expand Up @@ -575,7 +575,7 @@ def self.load_commands
RDF::Format.each do |format|
format.cli_commands.each do |command, options|
options = {lambda: options} unless options.is_a?(Hash)
add_command(command, options)
add_command(command, **options)
end
end
@commands_loaded = true
Expand Down Expand Up @@ -637,13 +637,13 @@ def self.parse(files, evaluate: nil, format: nil, encoding: Encoding::UTF_8, **o
r = RDF::Reader.for(format|| {sample: sample})
raise ArgumentError, "Unknown format for evaluated input" unless r
(@readers ||= []) << r
r.new(input, options) do |reader|
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|
RDF::Reader.open(file, **options) do |reader|
(@readers ||= []) << reader.class.to_s
yield(reader)
end
Expand Down
27 changes: 17 additions & 10 deletions lib/rdf/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def self.each(file_name: nil,
sample = case sample
when Proc then sample.call.to_s
else sample.dup.to_s
end.force_encoding(Encoding::ASCII_8BIT)
end.dup.force_encoding(Encoding::ASCII_8BIT)
# Given a sample, perform format detection across the appropriate formats, choosing the last that matches
# Return last format that has a positive detection
formats = formats.select {|f| f.detect(sample)}
Expand All @@ -145,10 +145,10 @@ def self.each(file_name: nil,
# @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
# @param [Hash{Symbol => Object}] options ({})
# @option options [String, #to_s] :file_name (nil)
# @option options [Symbol, #to_sym] :file_extension (nil)
# @option options [String, #to_s] :content_type (nil)
Expand All @@ -164,27 +164,34 @@ def self.each(file_name: nil,
# @yieldreturn [String] another way to provide a sample, allows lazy for retrieving the sample.
#
# @return [Class]
def self.for(*args, **options, &block)
def self.for(*arg, &block)
case arg.length
when 0 then arg = nil
when 1 then arg = arg.first
else
raise ArgumentError, "Format.for accepts zero or one argument, got #{arg.length}."
end

options = arg.is_a?(Hash) ? arg : {}
options = {sample: block}.merge(options) if block_given?
formats = case args.first
formats = case arg
when String, RDF::URI
# Find a format based on the file name
self.each(file_name: args.first, **options).to_a
self.each(file_name: arg, **options).to_a
when Symbol
# Try to find a match based on the full class name
# We want this to work even if autoloading fails
fmt = args.first
classes = self.each(options).select {|f| f.symbols.include?(fmt)}
classes = self.each(**options).select {|f| f.symbols.include?(arg)}
if classes.empty?
classes = case fmt
classes = case arg
when :ntriples then [RDF::NTriples::Format]
when :nquads then [RDF::NQuads::Format]
else []
end
end
classes
else
self.each(options.merge(all_if_none: false)).to_a
self.each(**options.merge(all_if_none: false)).to_a
end

# Return the last detected format
Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/mixin/enumerable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def has_triple?(triple)
def each_triple
if block_given?
each_statement do |statement|
yield *statement.to_triple
yield(*statement.to_triple)
end
end
enum_triple
Expand Down Expand Up @@ -282,7 +282,7 @@ def has_quad?(quad)
def each_quad
if block_given?
each_statement do |statement|
yield *statement.to_quad
yield(*statement.to_quad)
end
end
enum_quad
Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/mixin/mutable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def immutable?
# @option options [RDF::Resource] :graph_name
# Set set graph name of each loaded statement
# @return [void]
def load(url, graph_name: nil, **options)
def load(url, graph_name: nil, **options)
raise TypeError.new("#{self} is immutable") if immutable?

Reader.open(url, {base_uri: url}.merge(options)) do |reader|
Reader.open(url, base_uri: url, **options) do |reader|
if graph_name
statements = []
reader.each_statement do |statement|
Expand Down
8 changes: 4 additions & 4 deletions lib/rdf/mixin/queryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Queryable
#
# @example Querying for statements having a given predicate
# queryable.query([nil, RDF::Vocab::DOAP.developer, nil])
# queryable.query(predicate: RDF::Vocab::DOAP.developer) do |statement|
# queryable.query({predicate: RDF::Vocab::DOAP.developer}) do |statement|
# puts statement.inspect
# end
#
Expand Down Expand Up @@ -50,7 +50,7 @@ def query(pattern, **options, &block)
solutions = RDF::Query::Solutions.new
block = lambda {|solution| solutions << solution} unless block_given?
before_query(pattern) if respond_to?(:before_query)
query_execute(pattern, options, &block)
query_execute(pattern, **options, &block)
after_query(pattern) if respond_to?(:after_query)
# Returns the solutions, not an enumerator
solutions
Expand Down Expand Up @@ -85,7 +85,7 @@ def query(pattern, **options, &block)

# Otherwise, we delegate to `#query_pattern`:
else # pattern.variable?
query_pattern(pattern, options, &block)
query_pattern(pattern, **options, &block)
end
after_query(pattern) if respond_to?(:after_query)
enum
Expand Down Expand Up @@ -116,7 +116,7 @@ def query_execute(query, **options, &block)
# query execution by breaking down the query into its constituent
# triple patterns and invoking `RDF::Query::Pattern#execute` on each
# pattern.
query.execute(self, options, &block)
query.execute(self, **options, &block)
end
protected :query_execute

Expand Down
4 changes: 2 additions & 2 deletions lib/rdf/model/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def anonymous?
# @return [Integer]
# @see RDF::Enumerable#count
def count
@data.query(graph_name: graph_name || false).count
@data.query({graph_name: graph_name || false}).count
end

##
Expand All @@ -237,7 +237,7 @@ def has_statement?(statement)
# @see RDF::Enumerable#each_statement
def each(&block)
if @data.respond_to?(:query)
@data.query(graph_name: graph_name || false, &block)
@data.query({graph_name: graph_name || false}, &block)
elsif @data.respond_to?(:each)
@data.each(&block)
else
Expand Down

0 comments on commit 23f9e9a

Please sign in to comment.