Skip to content

Commit 2f7d8ce

Browse files
committed
Attempt to load json-ld-preloaded gem with silent fallback.
1 parent 5869d3d commit 2f7d8ce

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lib/json/ld/context.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
require 'json'
44
require 'bigdecimal'
55
require 'set'
6+
begin
7+
# Attempt to load this to avoid unnecessary context fetches
8+
require 'json-ld-preloaded'
9+
rescue LoadError
10+
# Silently allow this to fail
11+
end
612

713
module JSON::LD
814
class Context

script/parse

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,28 @@ def run(input, options)
3232
prefixes = {}
3333
start = Time.new
3434
if options[:flatten]
35-
output = JSON::LD::API.flatten(input, options.delete(:context), options)
35+
output = JSON::LD::API.flatten(input, options.delete(:context), **options)
3636
secs = Time.new - start
3737
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
3838
puts "Flattened in #{secs} seconds."
3939
elsif options[:expand]
4040
options = options.merge(expandContext: options.delete(:context)) if options.has_key?(:context)
41-
output = JSON::LD::API.expand(input, options)
41+
output = JSON::LD::API.expand(input, **options)
4242
secs = Time.new - start
4343
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
4444
puts "Expanded in #{secs} seconds."
4545
elsif options[:compact]
46-
output = JSON::LD::API.compact(input, options[:context], options)
46+
output = JSON::LD::API.compact(input, options[:context], **options)
4747
secs = Time.new - start
4848
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
4949
puts "Compacted in #{secs} seconds."
5050
elsif options[:frame]
51-
output = JSON::LD::API.frame(input, options[:frame], options)
51+
output = JSON::LD::API.frame(input, options[:frame], **options)
5252
secs = Time.new - start
5353
options[:output].puts output.to_json(JSON::LD::JSON_STATE)
5454
puts "Framed in #{secs} seconds."
5555
else
56-
r = reader_class.new(input, options[:parser_options])
56+
r = reader_class.new(input, **options[:parser_options])
5757
if options[:output_format] == :none
5858
num = 0
5959
r.each_statement { num += 1 } # Eat statements
@@ -63,7 +63,7 @@ def run(input, options)
6363
secs = Time.new - start
6464
num = g.count
6565
parser_options = options[:parser_options].merge(prefixes: r.prefixes, standard_prefixes: true)
66-
options[:output].puts g.dump(options[:output_format], parser_options)
66+
options[:output].puts g.dump(options[:output_format], **parser_options)
6767
puts
6868
end
6969
puts "Parsed #{num} statements in #{secs} seconds @ #{num/secs} statements/second."

0 commit comments

Comments
 (0)