Skip to content

Commit 455fa89

Browse files
committed
Finish 3.1.13
2 parents 73fcc5a + 2fcff5c commit 455fa89

5 files changed

Lines changed: 47 additions & 4 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.12
1+
3.1.13

lib/rdf/cli.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,7 @@ def to_hash
256256
lambda: ->(argv, opts) do
257257
writer_class = RDF::Writer.for(opts[:output_format]) || RDF::NTriples::Writer
258258
out = opts[:output]
259-
opts = opts.merge(prefixes: {})
260-
writer_opts = opts.merge(standard_prefixes: true)
259+
writer_opts = {prefixes: {}, standard_prefixes: true}.merge(opts)
261260
writer_class.new(out, **writer_opts) do |writer|
262261
writer << repository
263262
end
@@ -536,6 +535,8 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
536535
count = 0
537536
self.parse(args, **options) do |reader|
538537
reader.each_statement {|st| @repository << st}
538+
# Remember prefixes from reading
539+
options[:prefixes] ||= reader.prefixes
539540
end
540541
secs = Time.new - start
541542
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."

lib/rdf/query/solution.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ class RDF::Query
2323
class Solution
2424
# Undefine all superfluous instance methods:
2525
alias_method :__send, :send
26+
27+
# Temporarily remember instance method for deprecation message in `method_missing`.
28+
INSTANCE_METHODS = instance_methods
2629
undef_method(*instance_methods.
2730
map(&:to_s).
2831
select {|m| m.match?(/^\w+$/)}.
29-
reject {|m| %w(object_id dup instance_eval inspect to_s private_methods class should should_not pretty_print).include?(m) || m[0,2] == '__'}.
32+
reject {|m| %w(object_id dup instance_eval inspect to_s private_methods public_methods class method pretty_print).include?(m) || m[0,2] == '__'}.
3033
map(&:to_sym))
3134

3235
include Enumerable
@@ -344,6 +347,12 @@ def inspect
344347
# @return [RDF::Term]
345348
def method_missing(name, *args, &block)
346349
if args.empty? && @bindings.key?(name.to_sym)
350+
if INSTANCE_METHODS.include?(name)
351+
warn "[DEPRECATION] RDF::Query::Solution##{name} is an overridden instance method.\n" +
352+
"Its use as a solution accessor is deprecated and will be removed in a future version.\n" +
353+
"Use #[] for safe access.\n" +
354+
"Called from #{Gem.location_of_caller.join(':')}"
355+
end
347356
@bindings[name.to_sym]
348357
else
349358
super # raises NoMethodError

spec/cli_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@
180180
RDF::CLI.exec(["serialize", TEST_FILES[:nt]], output_format: :nquads)
181181
}.to write.to(:output)
182182
end
183+
184+
it "passes parsed prefixes to writer" do
185+
allow_any_instance_of(RDF::NTriples::Reader).to receive(:prefixes).and_return(foo: :bar)
186+
187+
writer_mock = double("writer")
188+
expect(RDF::Writer).to receive(:for).and_return(writer_mock)
189+
expect(writer_mock).to receive(:new).with(anything, hash_including(prefixes: {foo: :bar}))
190+
RDF::CLI.exec(["serialize", TEST_FILES[:nt]], output_format: :nquads)
191+
end
183192
end
184193

185194
it "help" do

spec/query_solution_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
end
1010
end
1111

12+
describe "accessors" do
13+
specify {expect(subject.a).to eq 1}
14+
specify {expect(subject[:a]).to eq 1}
15+
specify {expect(subject["a"]).to eq 1}
16+
specify {expect(subject["?b"]).to eq 2}
17+
specify {expect(subject["??c"]).to eq 3}
18+
specify {expect(subject["$d"]).to eq 4}
19+
specify {expect(subject["$$e"]).to eq 5}
20+
21+
context "with accessor overriding instance method" do
22+
subject {described_class.new(tap: 'foo')}
23+
24+
it "notes deprecation when accessor is an overriddedn instance method" do
25+
expect do
26+
expect(subject.tap).to eq 'foo'
27+
end.to write('[DEPRECATION]').to(:error)
28+
29+
expect do
30+
expect(subject[:tap]).to eq 'foo'
31+
end.not_to write.to(:error)
32+
end
33+
end
34+
end
35+
1236
describe "#each_binding" do
1337
it "returns an enumerator" do
1438
expect(subject.each_binding).to be_an Enumerator

0 commit comments

Comments
 (0)