diff --git a/.travis.yml b/.travis.yml index f044703..a649ce7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,21 +1,15 @@ -cache: bundler language: ruby -bundler_args: --without debug -script: "bundle exec rspec spec" -before_install: "gem update --system" env: - CI=true rvm: - - 2.2 - - 2.3 - 2.4 - 2.5 - - jruby-9 - - rbx-3 + - 2.6 + - 2.7 + - jruby cache: bundler sudo: false matrix: allow_failures: - - rvm: jruby-9 - - rvm: rbx-3 + - rvm: jruby dist: trusty diff --git a/Gemfile b/Gemfile index af7d5cf..32d1a6f 100644 --- a/Gemfile +++ b/Gemfile @@ -18,12 +18,6 @@ group :development, :test do gem 'rdf-vocab', git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop" gem 'sxp', git: "https://github.com/dryruby/sxp.rb", branch: "develop" gem "redcarpet", platform: :ruby - gem 'simplecov', require: false, platform: :mri - gem 'coveralls', require: false, platform: :mri -end - -platforms :rbx do - gem 'rubysl', '~> 2.0' - gem 'rubinius', '~> 2.0' - gem 'json' + gem 'simplecov', platforms: :mri + gem 'coveralls', '~> 0.8', platforms: :mri end diff --git a/VERSION b/VERSION index cb2b00e..fd2a018 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.0.1 +3.1.0 diff --git a/lib/rdf/trig/streaming_writer.rb b/lib/rdf/trig/streaming_writer.rb index 7c950aa..23d14c3 100644 --- a/lib/rdf/trig/streaming_writer.rb +++ b/lib/rdf/trig/streaming_writer.rb @@ -11,24 +11,24 @@ def stream_statement(statement) if statement.graph_name != @streaming_graph stream_epilogue if statement.graph_name - @output.write "#{format_term(statement.graph_name, options)} {" + @output.write "#{format_term(statement.graph_name, **options)} {" end @streaming_graph, @streaming_subject, @streaming_predicate = statement.graph_name, statement.subject, statement.predicate - @output.write "#{format_term(statement.subject, options)} " - @output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} " + @output.write "#{format_term(statement.subject, **options)} " + @output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} " elsif statement.subject != @streaming_subject @output.puts " ." if @previous_statement @output.write "#{indent(@streaming_subject ? 1 : 0)}" @streaming_subject, @streaming_predicate = statement.subject, statement.predicate - @output.write "#{format_term(statement.subject, options)} " - @output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} " + @output.write "#{format_term(statement.subject, **options)} " + @output.write "#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} " elsif statement.predicate != @streaming_predicate @streaming_predicate = statement.predicate - @output.write ";\n#{indent(@streaming_subject ? 2 : 1)}#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, options)} " + @output.write ";\n#{indent(@streaming_subject ? 2 : 1)}#{statement.predicate == RDF.type ? 'a' : format_term(statement.predicate, **options)} " else @output.write ",\n#{indent(@streaming_subject ? 3 : 2)}" end - @output.write("#{format_term(statement.object, options)}") + @output.write("#{format_term(statement.object, **options)}") @previous_statement = statement end diff --git a/lib/rdf/trig/writer.rb b/lib/rdf/trig/writer.rb index df937c6..f6641bd 100644 --- a/lib/rdf/trig/writer.rb +++ b/lib/rdf/trig/writer.rb @@ -87,7 +87,7 @@ class Writer < RDF::Turtle::Writer # @yieldreturn [void] # @yield [writer] # @yieldparam [RDF::Writer] writer - def initialize(output = $stdout, options = {}, &block) + def initialize(output = $stdout, **options, &block) super do # Set both @repo and @graph to a new repository. @repo = @graph = RDF::Repository.new @@ -100,7 +100,6 @@ def initialize(output = $stdout, options = {}, &block) end end - ## # Adds a triple to be serialized # @param [RDF::Resource] subject @@ -197,8 +196,8 @@ def blankNodePropertyList?(resource, position) end def resource_in_single_graph?(resource) - graph_names = @repo.query(subject: resource).map(&:graph_name) - graph_names += @repo.query(object: resource).map(&:graph_name) + graph_names = @repo.query({subject: resource}).map(&:graph_name) + graph_names += @repo.query({object: resource}).map(&:graph_name) graph_names.uniq.length <= 1 end @@ -208,7 +207,7 @@ def order_graphs graph_names = @repo.graph_names.to_a.sort # include default graph, if necessary - graph_names.unshift(nil) unless @repo.query(graph_name: false).to_a.empty? + graph_names.unshift(nil) unless @repo.query({graph_name: false}).to_a.empty? graph_names end diff --git a/rdf-trig.gemspec b/rdf-trig.gemspec index cd159e6..0c3712f 100755 --- a/rdf-trig.gemspec +++ b/rdf-trig.gemspec @@ -18,18 +18,18 @@ Gem::Specification.new do |gem| gem.files = %w(AUTHORS README.md History UNLICENSE VERSION) + Dir.glob('lib/**/*.rb') gem.require_paths = %w(lib) - gem.required_ruby_version = '>= 2.2.2' + gem.required_ruby_version = '>= 2.4' gem.requirements = [] - gem.add_runtime_dependency 'rdf', '~> 3.0' + gem.add_runtime_dependency 'rdf', '~> 3.1' gem.add_runtime_dependency 'ebnf', '~> 1.1' - gem.add_runtime_dependency 'rdf-turtle', '~> 3.0', '>= 3.0.3' - gem.add_development_dependency 'json-ld', '~> 3.0' - gem.add_development_dependency 'rspec', '~> 3.7' - gem.add_development_dependency 'rspec-its', '~> 1.2' - gem.add_development_dependency 'rdf-isomorphic', '~> 3.0' - gem.add_development_dependency 'yard' , '~> 0.9.12' - gem.add_development_dependency 'rdf-spec', '~> 3.0' - gem.add_development_dependency 'rake', '~> 12.0' + gem.add_runtime_dependency 'rdf-turtle', '~> 3.1' + gem.add_development_dependency 'json-ld', '~> 3.1' + gem.add_development_dependency 'rspec', '~> 3.9' + gem.add_development_dependency 'rspec-its', '~> 1.3' + gem.add_development_dependency 'rdf-isomorphic', '~> 3.1' + gem.add_development_dependency 'yard' , '~> 0.9.20' + gem.add_development_dependency 'rdf-spec', '~> 3.1' + gem.add_development_dependency 'rake', '~> 13.0' gem.post_install_message = nil end diff --git a/script/parse b/script/parse index d390f57..e83933c 100755 --- a/script/parse +++ b/script/parse @@ -9,7 +9,7 @@ require 'rdf/nquads' require 'ebnf/ll1/parser' require 'getoptlong' -def run(input, options) +def run(input, **options) if options[:profile] require 'profiler' end @@ -33,15 +33,15 @@ def run(input, options) end end elsif options[:output_format] == :inspect - reader_class.new(input, options[:parser_options]).each do |statement| + reader_class.new(input, **options[:parser_options]).each do |statement| num += 1 options[:output].puts statement.inspect end else - r = reader_class.new(input, options[:parser_options]) + r = reader_class.new(input, **options[:parser_options]) g = RDF::Repository.new << r num = g.count - options[:output].puts g.dump(options[:output_format], {:prefixes => r.prefixes}.merge(options[:writer_options])) + options[:output].puts g.dump(options[:output_format], prefixes: r.prefixes, **options[:writer_options]) end if options[:profile] Profiler__::stop_profile @@ -122,10 +122,10 @@ end if ARGV.empty? s = input ? input : $stdin.read - run(StringIO.new(s), options) + run(StringIO.new(s), **options) else ARGV.each do |test_file| - run(Kernel.open(test_file), options) + run(Kernel.open(test_file), **options) end end puts diff --git a/script/tc b/script/tc index c27a7ac..63bc707 100755 --- a/script/tc +++ b/script/tc @@ -12,7 +12,7 @@ require 'getoptlong' ASSERTOR = "http://greggkellogg.net/foaf#me" RUN_TIME = Time.now -def earl_preamble(options) +def earl_preamble(**options) options[:output].write File.read(File.expand_path("../../etc/doap#{'-nquads' if options[:nquads]}.ttl", __FILE__)) options[:output].puts %( <> foaf:primaryTopic ; @@ -43,7 +43,7 @@ def earl_preamble(options) ) end -def run_tc(tc, options) +def run_tc(tc, **options) STDERR.write "run #{tc.name}" if options[:verbose] @@ -63,7 +63,7 @@ def run_tc(tc, options) validate: true }.merge(options) - reader = RDF::Reader.for(tc.action).new(tc.input, options) + reader = RDF::Reader.for(tc.action).new(tc.input, **options) graph = RDF::Repository.new result = nil @@ -142,7 +142,7 @@ opts = GetoptLong.new( ["--verbose", "-v", GetoptLong::NO_ARGUMENT] ) -def help(options) +def help(**options) puts "Usage: #{$0} [options] [test-number ...]" puts "Options:" puts " --debug: Display detailed debug output" @@ -159,7 +159,7 @@ end opts.each do |opt, arg| case opt - when '--help' then help(options) + when '--help' then help(**options) when '--dbg' then logger.level = Logger::DEBUG when '--earl' options[:quiet] = options[:earl] = true @@ -177,7 +177,7 @@ end manifests = (options[:nquads] ? [Fixtures::SuiteTest::NQBASE] : [Fixtures::SuiteTest::BASE]).map {|b| b + "manifest.ttl"} -earl_preamble(options) if options[:earl] +earl_preamble(**options) if options[:earl] result_count = {} @@ -185,7 +185,7 @@ manifests.each do |manifest| Fixtures::SuiteTest::Manifest.open(manifest) do |m| m.entries.each do |tc| next unless ARGV.empty? || ARGV.any? {|n| tc.name.match(/#{n}/)} - run_tc(tc, options.merge(result_count: result_count)) + run_tc(tc, result_count: result_count, **options) end end end diff --git a/spec/reader_spec.rb b/spec/reader_spec.rb index 0f02918..9851ac4 100644 --- a/spec/reader_spec.rb +++ b/spec/reader_spec.rb @@ -931,7 +931,7 @@ end end - def parse(input, options = {}) + def parse(input, **options) @logger = RDF::Spec.logger options = { logger: @logger, @@ -939,7 +939,7 @@ def parse(input, options = {}) canonicalize: false, }.merge(options) graph = options[:graph] || RDF::Repository.new - RDF::TriG::Reader.new(input, options).each do |statement| + RDF::TriG::Reader.new(input, **options).each do |statement| graph << statement end graph diff --git a/spec/suite_helper.rb b/spec/suite_helper.rb index e452e37..1ceb420 100644 --- a/spec/suite_helper.rb +++ b/spec/suite_helper.rb @@ -6,9 +6,9 @@ # For now, override RDF::Utils::File.open_file to look for the file locally before attempting to retrieve it module RDF::Util module File - REMOTE_PATH = "http://www.w3.org/2013/TriGTests/" + REMOTE_PATH = "http://w3c.github.io/rdf-tests/trig/" LOCAL_PATH = ::File.expand_path("../w3c-rdf/trig", __FILE__) + '/' - REMOTE_PATH_NQ = "http://www.w3.org/2013/N-QuadsTests/" + REMOTE_PATH_NQ = "http://w3c.github.io/rdf-tests/nquads/" LOCAL_PATH_NQ = ::File.expand_path("../w3c-rdf/nquads", __FILE__) + '/' class << self @@ -24,7 +24,7 @@ class << self # HTTP Request headers. # @return [IO] File stream # @yield [IO] File stream - def self.open_file(filename_or_url, options = {}, &block) + def self.open_file(filename_or_url, **options, &block) case when filename_or_url.to_s =~ /^file:/ path = filename_or_url[5..-1] @@ -57,7 +57,7 @@ def self.open_file(filename_or_url, options = {}, &block) # For overriding content type from test data document_options[:headers][:content_type] = options[:contentType] if options[:contentType] - remote_document = RDF::Util::File::RemoteDocument.new(response.read, document_options) + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) if block_given? yield remote_document else @@ -91,14 +91,14 @@ def self.open_file(filename_or_url, options = {}, &block) # For overriding content type from test data document_options[:headers][:content_type] = options[:contentType] if options[:contentType] - remote_document = RDF::Util::File::RemoteDocument.new(response.read, document_options) + remote_document = RDF::Util::File::RemoteDocument.new(response.read, **document_options) if block_given? yield remote_document else remote_document end else - original_open_file(filename_or_url, options, &block) + original_open_file(filename_or_url, **options, &block) end end end @@ -106,8 +106,8 @@ def self.open_file(filename_or_url, options = {}, &block) module Fixtures module SuiteTest - BASE = "http://www.w3.org/2013/TriGTests/" - NQBASE = "http://www.w3.org/2013/N-QuadsTests/" + BASE = "http://w3c.github.io/rdf-tests/trig/" + NQBASE = "http://w3c.github.io/rdf-tests/nquads/" FRAME = JSON.parse(%q({ "@context": { "xsd": "http://www.w3.org/2001/XMLSchema#", @@ -131,7 +131,7 @@ def self.open(file) g = RDF::Repository.load(file, format: :turtle) JSON::LD::API.fromRDF(g) do |expanded| JSON::LD::API.frame(expanded, FRAME) do |framed| - yield Manifest.new(framed['@graph'].first) + yield Manifest.new(framed) end end end diff --git a/spec/writer_spec.rb b/spec/writer_spec.rb index fb70a3a..f8ae4c7 100644 --- a/spec/writer_spec.rb +++ b/spec/writer_spec.rb @@ -52,11 +52,11 @@ }, }.each do |name, params| it name do - serialize(params[:input], params[:regexp], params) + serialize(params[:input], params[:regexp], **params) end it "#{name} (stream)" do - serialize(params[:input], params.fetch(:regexp_stream, params[:regexp]), params.merge(stream: true)) + serialize(params[:input], params.fetch(:regexp_stream, params[:regexp]), stream: true, **params) end end end @@ -115,8 +115,8 @@ } ), [ - %r(^ \[ a \] \.)m, - %r(^ \{\s* \[ a \] \.\s*\})m + %r(^ \[\s*a \s*\] \.)m, + %r(^ \{\s* \[\s*a \s*\] \.\s*\})m ], [ %r(^ _:c \.)m, @@ -341,9 +341,9 @@ end end unless ENV['CI'] - def parse(input, options = {}) + def parse(input, **options) reader = RDF::Reader.for(options.fetch(:format, :trig)) - reader.new(input, options, &:each).to_a.extend(RDF::Enumerable) + reader.new(input, **options, &:each).to_a.extend(RDF::Enumerable) end # Serialize ntstr to a string and compare against regexps @@ -351,12 +351,13 @@ def serialize(ntstr, regexps = [], base_uri: nil, **options) prefixes = options[:prefixes] || {} repo = ntstr.is_a?(RDF::Enumerable) ? ntstr : parse(ntstr, base_uri: base_uri, prefixes: prefixes, validate: false, logger: [], **options) logger.info "serialized: #{ntstr}" - result = RDF::TriG::Writer.buffer(options.merge( + result = RDF::TriG::Writer.buffer( logger: logger, base_uri: base_uri, prefixes: prefixes, - encoding: Encoding::UTF_8 - )) do |writer| + encoding: Encoding::UTF_8, + **options + ) do |writer| writer << repo end