Skip to content

Commit 5830807

Browse files
committed
Many fixes for hash arguments at last position being handled differently in Ruby 2.7.
Prep for 3.1 release.
1 parent 32cc77e commit 5830807

21 files changed

+86
-88
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ group :development do
1212
gem 'rack-linkeddata', git: "https://github.com/ruby-rdf/rack-linkeddata", branch: "develop"
1313
gem 'rdf-spec', git: "https://github.com/ruby-rdf/rdf-spec", branch: "develop"
1414
gem 'rdf-isomorphic', git: "https://github.com/ruby-rdf/rdf-isomorphic", branch: "develop"
15+
gem 'rdf-turtle', git: "https://github.com/ruby-rdf/rdf-turtle", branch: "develop"
1516
gem 'rdf-trig', git: "https://github.com/ruby-rdf/rdf-trig", branch: "develop"
1617
gem 'rdf-vocab', git: "https://github.com/ruby-rdf/rdf-vocab", branch: "develop"
1718
gem 'rdf-xsd', git: "https://github.com/ruby-rdf/rdf-xsd", branch: "develop"

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ Note, the API method signatures differed in versions before 1.0, in that they al
502502
* {JSON::LD::Writer}
503503

504504
## Dependencies
505-
* [Ruby](https://ruby-lang.org/) (>= 2.2.2)
506-
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.0)
507-
* [JSON](https://rubygems.org/gems/json) (>= 2.1)
505+
* [Ruby](https://ruby-lang.org/) (>= 2.4)
506+
* [RDF.rb](https://rubygems.org/gems/rdf) (~> 3.1)
507+
* [JSON](https://rubygems.org/gems/json) (>= 2.2)
508508

509509
## Installation
510510
The recommended installation method is via [RubyGems](https://rubygems.org/).

VERSION

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

json-ld.gemspec

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ Gem::Specification.new do |gem|
2424
gem.require_paths = %w(lib)
2525
gem.test_files = Dir.glob('spec/**/*.rb') + Dir.glob('spec/test-files/*')
2626

27-
gem.required_ruby_version = '>= 2.2.2'
27+
gem.required_ruby_version = '>= 2.4'
2828
gem.requirements = []
29-
gem.add_runtime_dependency 'rdf', '~> 3.0', '>= 3.0.13'
29+
gem.add_runtime_dependency 'rdf', '~> 3.1'
3030
gem.add_runtime_dependency 'multi_json', '~> 1.14'
3131
gem.add_runtime_dependency 'i18n', '<= 1.5.1' if ruby_version < "2.3"
3232
gem.add_runtime_dependency 'link_header', '~> 0.0', '>= 0.0.8'
@@ -39,9 +39,9 @@ Gem::Specification.new do |gem|
3939
gem.add_development_dependency 'yajl-ruby', '~> 1.4' unless is_java
4040
gem.add_development_dependency 'rack-test', '~> 1.1'
4141
gem.add_development_dependency 'rdf-isomorphic', '~> 3.0'
42-
gem.add_development_dependency 'rdf-spec', '~> 3.0'
43-
gem.add_development_dependency 'rdf-trig', '~> 3.0'
44-
gem.add_development_dependency 'rdf-turtle', '~> 3.0'
42+
gem.add_development_dependency 'rdf-spec', '~> 3.1'
43+
gem.add_development_dependency 'rdf-trig', '~> 3.1'
44+
gem.add_development_dependency 'rdf-turtle', '~> 3.1'
4545
gem.add_development_dependency 'rdf-vocab', '~> 3.0'
4646
gem.add_development_dependency 'rdf-xsd', '~> 3.0'
4747
gem.add_development_dependency 'rspec', '~> 3.9'

lib/json/ld/api.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **opti
121121

122122
case remote_doc.document
123123
when String
124-
MultiJson.load(remote_doc.document, options)
124+
MultiJson.load(remote_doc.document, **options)
125125
else
126126
# Already parsed
127127
remote_doc.document
@@ -130,7 +130,7 @@ def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **opti
130130

131131
# If not provided, first use context from document, or from a Link header
132132
context ||= context_ref || {}
133-
@context = Context.parse(context || {}, @options)
133+
@context = Context.parse(context || {}, **@options)
134134

135135
if block_given?
136136
case block.arity
@@ -164,7 +164,7 @@ def initialize(input, context, rename_bnodes: true, unique_bnodes: false, **opti
164164
# @see https://www.w3.org/TR/json-ld11-api/#expansion-algorithm
165165
def self.expand(input, framing: false, **options, &block)
166166
result, doc_base = nil
167-
API.new(input, options[:expandContext], options) do
167+
API.new(input, options[:expandContext], **options) do
168168
result = self.expand(self.value, nil, self.context,
169169
ordered: @options[:ordered],
170170
framing: framing)
@@ -217,7 +217,7 @@ def self.compact(input, context, expanded: false, **options)
217217

218218
# 1) Perform the Expansion Algorithm on the JSON-LD input.
219219
# This removes any existing context to allow the given context to be cleanly applied.
220-
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false)) do |res, base_iri|
220+
expanded_input = expanded ? input : API.expand(input, ordered: false, **options) do |res, base_iri|
221221
options[:base] ||= base_iri if options[:compactToRelative]
222222
res
223223
end
@@ -264,7 +264,7 @@ def self.flatten(input, context, expanded: false, **options)
264264
}.merge(options)
265265

266266
# Expand input to simplify processing
267-
expanded_input = expanded ? input : API.expand(input, options) do |result, base_iri|
267+
expanded_input = expanded ? input : API.expand(input, **options) do |result, base_iri|
268268
options[:base] ||= base_iri if options[:compactToRelative]
269269
result
270270
end
@@ -368,13 +368,13 @@ def self.frame(input, frame, expanded: false, **options)
368368
end
369369

370370
# Expand input to simplify processing
371-
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false)) do |res, base_iri|
371+
expanded_input = expanded ? input : API.expand(input, ordered: false, **options) do |res, base_iri|
372372
options[:base] ||= base_iri if options[:compactToRelative]
373373
res
374374
end
375375

376376
# Expand frame to simplify processing
377-
expanded_frame = API.expand(frame, options.merge(framing: true, ordered: false))
377+
expanded_frame = API.expand(frame, framing: true, ordered: false, **options)
378378

379379
# Initialize input using frame as context
380380
API.new(expanded_input, frame['@context'], no_default_base: true, **options) do
@@ -463,7 +463,7 @@ def self.toRdf(input, expanded: false, **options, &block)
463463
unless block_given?
464464
results = []
465465
results.extend(RDF::Enumerable)
466-
self.toRdf(input, options) do |stmt|
466+
self.toRdf(input, **options) do |stmt|
467467
results << stmt
468468
end
469469
return results
@@ -474,9 +474,9 @@ def self.toRdf(input, expanded: false, **options, &block)
474474
}.merge(options)
475475

476476
# Expand input to simplify processing
477-
expanded_input = expanded ? input : API.expand(input, options.merge(ordered: false))
477+
expanded_input = expanded ? input : API.expand(input, ordered: false, **options)
478478

479-
API.new(expanded_input, nil, options) do
479+
API.new(expanded_input, nil, **options) do
480480
# 1) Perform the Expansion Algorithm on the JSON-LD input.
481481
# This removes any existing context to allow the given context to be cleanly applied.
482482
log_debug(".toRdf") {"expanded input: #{expanded_input.to_json(JSON_STATE) rescue 'malformed json'}"}
@@ -518,7 +518,7 @@ def self.toRdf(input, expanded: false, **options, &block)
518518
def self.fromRdf(input, useRdfType: false, useNativeTypes: false, **options, &block)
519519
result = nil
520520

521-
API.new(nil, nil, options) do
521+
API.new(nil, nil, **options) do
522522
result = from_statements(input,
523523
useRdfType: useRdfType,
524524
useNativeTypes: useNativeTypes,
@@ -622,7 +622,7 @@ def self.loadRemoteDocument(url,
622622
end
623623
else
624624
validate_input(remote_doc.document, url: remote_doc.documentUrl) if validate
625-
MultiJson.load(remote_doc.document, options)
625+
MultiJson.load(remote_doc.document, **options)
626626
end
627627
end
628628

@@ -667,7 +667,7 @@ def self.documentLoader(url, extractAllScripts: false, profile: nil, requestProf
667667
contentType: content_type,
668668
contextUrl: context_url))
669669
else
670-
RDF::Util::File.open_file(url, options, &block)
670+
RDF::Util::File.open_file(url, **options, &block)
671671
end
672672
end
673673

@@ -710,7 +710,7 @@ def self.load_html(input, url:,
710710
self.extend(@implementation)
711711

712712
input = begin
713-
initialize_html(input, options)
713+
initialize_html(input, **options)
714714
rescue
715715
raise JSON::LD::JsonLdError::LoadingDocumentFailed, "Malformed HTML document: #{$!.message}"
716716
end
@@ -733,7 +733,7 @@ def self.load_html(input, url:,
733733
raise JSON::LD::JsonLdError::InvalidScriptElement, "Script tag has type=#{element.attributes['type']}" unless element.attributes['type'].to_s.start_with?('application/ld+json')
734734
content = element.inner_html
735735
validate_input(content, url: url) if options[:validate]
736-
MultiJson.load(content, options)
736+
MultiJson.load(content, **options)
737737
elsif extractAllScripts
738738
res = []
739739
elements = if profile
@@ -747,7 +747,7 @@ def self.load_html(input, url:,
747747
elements.each do |element|
748748
content = element.inner_html
749749
validate_input(content, url: url) if options[:validate]
750-
r = MultiJson.load(content, options)
750+
r = MultiJson.load(content, **options)
751751
if r.is_a?(Hash)
752752
res << r
753753
elsif r.is_a?(Array)
@@ -761,7 +761,7 @@ def self.load_html(input, url:,
761761
element ||= input.at_xpath("//script[starts-with(@type, 'application/ld+json')]")
762762
content = element ? element.inner_html : "[]"
763763
validate_input(content, url: url) if options[:validate]
764-
MultiJson.load(content, options)
764+
MultiJson.load(content, **options)
765765
end
766766
rescue JSON::LD::JsonLdError::LoadingDocumentFailed, MultiJson::ParseError => e
767767
raise JSON::LD::JsonLdError::InvalidScriptElement, e.message

lib/json/ld/conneg.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ContentNegotiation
3333
# @return [void]
3434
def self.registered(app)
3535
options = {}
36-
app.use(JSON::LD::Rack, options)
36+
app.use(JSON::LD::Rack, **options)
3737
end
3838

3939
def initialize(app)

lib/json/ld/context.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def inspect
318318
# on a remote context load error, syntax error, or a reference to a term which is not defined.
319319
# @return [Context]
320320
def self.parse(local_context, protected: false, override_protected: false, propagate: true, **options)
321-
self.new(options).parse(local_context, protected: false, override_protected: override_protected, propagate: propagate)
321+
self.new(**options).parse(local_context, protected: false, override_protected: override_protected, propagate: propagate)
322322
end
323323

324324
##
@@ -492,7 +492,7 @@ def vocab=(value, **options)
492492
#
493493
# @param [Boolean] value
494494
def propagate=(value, **options)
495-
raise JsonLdError::InvalidContextMember, "@propagate may only be set in 1.1 mode}" if processingMode("json-ld-1.0")
495+
raise JsonLdError::InvalidContextMember, "@propagate may only be set in 1.1 mode" if processingMode("json-ld-1.0")
496496
raise JsonLdError::InvalidPropagateValue, "@propagate must be boolean valued: #{value.inspect}" unless value.is_a?(TrueClass) || value.is_a?(FalseClass)
497497
value
498498
end
@@ -530,7 +530,7 @@ def parse(local_context, remote_contexts: [], protected: false, override_protect
530530
when nil
531531
# 3.1 If the `override_protected` is false, and the active context contains protected terms, an error is raised.
532532
if override_protected || result.term_definitions.values.none?(&:protected?)
533-
null_context = Context.new(options)
533+
null_context = Context.new(**options)
534534
null_context.previous_context = result unless propagate
535535
result = null_context
536536
else
@@ -559,10 +559,8 @@ def parse(local_context, remote_contexts: [], protected: false, override_protect
559559

560560
# 3.2.1) Set context to the result of resolving value against the base IRI which is established as specified in section 5.1 Establishing a Base URI of [RFC3986]. Only the basic algorithm in section 5.2 of [RFC3986] is used; neither Syntax-Based Normalization nor Scheme-Based Normalization are performed. Characters additionally allowed in IRI references are treated in the same way that unreserved characters are treated in URI references, per section 6.5 of [RFC3987].
561561
context = RDF::URI(result.context_base || options[:base]).join(context)
562-
context_canon = RDF::URI(context).canonicalize
563-
if context_canon.scheme == 'https'
564-
context_canon = RDF::URI(context_canon.to_h.merge(scheme: 'http'))
565-
end
562+
context_canon = context.canonicalize
563+
context_canon.scheme == 'http' if context_canon.scheme == 'https'
566564

567565
remote_contexts << context.to_s
568566
raise JsonLdError::ContextOverflow, "#{context}" if remote_contexts.length >= MAX_CONTEXTS_LOADED
@@ -589,7 +587,7 @@ def parse(local_context, remote_contexts: [], protected: false, override_protect
589587
requestProfile: 'http://www.w3.org/ns/json-ld#context',
590588
base: nil)
591589
#context_opts.delete(:headers)
592-
JSON::LD::API.loadRemoteDocument(context.to_s, context_opts) do |remote_doc|
590+
JSON::LD::API.loadRemoteDocument(context.to_s, **context_opts) do |remote_doc|
593591
# 3.2.5) Dereference context. If the dereferenced document has no top-level JSON object with an @context member, an invalid remote context has been detected and processing is aborted; otherwise, set context to the value of that member.
594592
raise JsonLdError::InvalidRemoteContext, "#{context}" unless remote_doc.document.is_a?(Hash) && remote_doc.document.has_key?('@context')
595593
context = remote_doc.document['@context']
@@ -637,7 +635,7 @@ def parse(local_context, remote_contexts: [], protected: false, override_protect
637635
requestProfile: 'http://www.w3.org/ns/json-ld#context',
638636
base: nil)
639637
context_opts.delete(:headers)
640-
JSON::LD::API.loadRemoteDocument(source, context_opts) do |remote_doc|
638+
JSON::LD::API.loadRemoteDocument(source, **context_opts) do |remote_doc|
641639
# Dereference source. If the dereferenced document has no top-level JSON object with an @context member, an invalid remote context has been detected and processing is aborted; otherwise, set context to the value of that member.
642640
raise JsonLdError::InvalidRemoteContext, "#{source}" unless remote_doc.document.is_a?(Hash) && remote_doc.document.has_key?('@context')
643641
import_context = remote_doc.document['@context']
@@ -666,7 +664,6 @@ def parse(local_context, remote_contexts: [], protected: false, override_protect
666664
# ... where key is not @base, @vocab, @language, or @version
667665
result.create_term_definition(context, key, defined,
668666
override_protected: override_protected,
669-
propagate: propagate,
670667
protected: context.fetch('@protected', protected)) unless NON_TERMDEF_KEYS.include?(key)
671668
end
672669
else
@@ -732,7 +729,7 @@ def merge!(context)
732729
# @raise [JsonLdError]
733730
# Represents a cyclical term dependency
734731
# @see https://www.w3.org/TR/json-ld11-api/index.html#create-term-definition
735-
def create_term_definition(local_context, term, defined, override_protected: false, propagate: true, protected: false)
732+
def create_term_definition(local_context, term, defined, override_protected: false, protected: false)
736733
# Expand a string value, unless it matches a keyword
737734
#log_debug("create_term_definition") {"term = #{term.inspect}"}
738735

0 commit comments

Comments
 (0)