Skip to content

Commit 1e52830

Browse files
committed
Use an RDF::OrderedRepo in CLI if the ordered option is provided and the gem is loaded; otherwise, use an extended Array.
1 parent ffe61cb commit 1e52830

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

lib/rdf/cli.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
require 'linkeddata'
99
rescue LoadError
1010
# Silently load without linkeddata, but try some others
11-
%w(microdata n3 rdfa rdfxml reasoner tabular trig trix turtle vocab xsd json/ld ld/patch).each do |ser|
11+
%w(microdata ordered_repo n3 rdfa rdfxml reasoner tabular trig trix turtle vocab xsd json/ld ld/patch).each do |ser|
1212
begin
1313
require ser.include?('/') ? ser : "rdf/#{ser}"
1414
rescue LoadError
@@ -506,10 +506,12 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
506506
options[:output_format] = options[:output_format].to_sym if options[:output_format]
507507

508508
# Allow repository to be set via option.
509-
@repository = options[:repository] ||
510-
(options[:ordered] ?
511-
[].extend(RDF::Enumerable, RDF::Queryable) :
512-
RDF::Repository.new)
509+
# If RDF::OrderedRepo is present, use it if the `ordered` option is specified, otherwise extend an Array.
510+
@repository = options[:repository] || case
511+
when RDF.const_defined?(:OrderedRepo) then RDF::OrderedRepo.new
512+
when options[:ordered] then [].extend(RDF::Enumerable, RDF::Queryable)
513+
else RDF::Repository.new
514+
end
513515

514516
# Parse input files if any command requires it
515517
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}

0 commit comments

Comments
 (0)