Skip to content

Commit

Permalink
Finish 3.1.13
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Mar 6, 2021
2 parents 73fcc5a + 2fcff5c commit 455fa89
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.12
3.1.13
5 changes: 3 additions & 2 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ def to_hash
lambda: ->(argv, opts) do
writer_class = RDF::Writer.for(opts[:output_format]) || RDF::NTriples::Writer
out = opts[:output]
opts = opts.merge(prefixes: {})
writer_opts = opts.merge(standard_prefixes: true)
writer_opts = {prefixes: {}, standard_prefixes: true}.merge(opts)
writer_class.new(out, **writer_opts) do |writer|
writer << repository
end
Expand Down Expand Up @@ -536,6 +535,8 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
count = 0
self.parse(args, **options) do |reader|
reader.each_statement {|st| @repository << st}
# Remember prefixes from reading
options[:prefixes] ||= reader.prefixes
end
secs = Time.new - start
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."
Expand Down
11 changes: 10 additions & 1 deletion lib/rdf/query/solution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class RDF::Query
class Solution
# Undefine all superfluous instance methods:
alias_method :__send, :send

# Temporarily remember instance method for deprecation message in `method_missing`.
INSTANCE_METHODS = instance_methods
undef_method(*instance_methods.
map(&:to_s).
select {|m| m.match?(/^\w+$/)}.
reject {|m| %w(object_id dup instance_eval inspect to_s private_methods class should should_not pretty_print).include?(m) || m[0,2] == '__'}.
reject {|m| %w(object_id dup instance_eval inspect to_s private_methods public_methods class method pretty_print).include?(m) || m[0,2] == '__'}.
map(&:to_sym))

include Enumerable
Expand Down Expand Up @@ -344,6 +347,12 @@ def inspect
# @return [RDF::Term]
def method_missing(name, *args, &block)
if args.empty? && @bindings.key?(name.to_sym)
if INSTANCE_METHODS.include?(name)
warn "[DEPRECATION] RDF::Query::Solution##{name} is an overridden instance method.\n" +
"Its use as a solution accessor is deprecated and will be removed in a future version.\n" +
"Use #[] for safe access.\n" +
"Called from #{Gem.location_of_caller.join(':')}"
end
@bindings[name.to_sym]
else
super # raises NoMethodError
Expand Down
9 changes: 9 additions & 0 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@
RDF::CLI.exec(["serialize", TEST_FILES[:nt]], output_format: :nquads)
}.to write.to(:output)
end

it "passes parsed prefixes to writer" do
allow_any_instance_of(RDF::NTriples::Reader).to receive(:prefixes).and_return(foo: :bar)

writer_mock = double("writer")
expect(RDF::Writer).to receive(:for).and_return(writer_mock)
expect(writer_mock).to receive(:new).with(anything, hash_including(prefixes: {foo: :bar}))
RDF::CLI.exec(["serialize", TEST_FILES[:nt]], output_format: :nquads)
end
end

it "help" do
Expand Down
24 changes: 24 additions & 0 deletions spec/query_solution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
end
end

describe "accessors" do
specify {expect(subject.a).to eq 1}
specify {expect(subject[:a]).to eq 1}
specify {expect(subject["a"]).to eq 1}
specify {expect(subject["?b"]).to eq 2}
specify {expect(subject["??c"]).to eq 3}
specify {expect(subject["$d"]).to eq 4}
specify {expect(subject["$$e"]).to eq 5}

context "with accessor overriding instance method" do
subject {described_class.new(tap: 'foo')}

it "notes deprecation when accessor is an overriddedn instance method" do
expect do
expect(subject.tap).to eq 'foo'
end.to write('[DEPRECATION]').to(:error)

expect do
expect(subject[:tap]).to eq 'foo'
end.not_to write.to(:error)
end
end
end

describe "#each_binding" do
it "returns an enumerator" do
expect(subject.each_binding).to be_an Enumerator
Expand Down

0 comments on commit 455fa89

Please sign in to comment.