Skip to content

Commit b0e1391

Browse files
authored
Merge pull request #344 from ruby-rdf/feature/Informative-Deprecations
Feature/informative deprecations
2 parents a970d14 + 02c0752 commit b0e1391

6 files changed

Lines changed: 21 additions & 9 deletions

File tree

lib/rdf.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,7 @@ def self.Node(*args, &block)
9494
# @param (see RDF::URI#initialize)
9595
# @return [RDF::URI]
9696
def self.URI(*args, &block)
97-
case uri = args.first
98-
when uri.respond_to?(:to_uri) then uri.to_uri
99-
else URI.new(*args, &block)
100-
end
97+
(uri = args.first).respond_to?(:to_uri) ? uri.to_uri : URI.new(*args, &block)
10198
end
10299

103100
##

lib/rdf/mixin/enumerable.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,10 @@ def dump(*args, **options)
765765
def method_missing(meth, *args)
766766
case meth
767767
when :to_hash
768-
warn "[DEPRECATION] Enumerable#to_hash is deprecated, use Enumerable#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
768+
warn "[DEPRECATION] RDF::Enumerable#to_hash is deprecated, use RDF::Enumerable#to_h instead.\n" +
769+
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
770+
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
771+
"Called from #{Gem.location_of_caller.join(':')}"
769772
return self.to_h
770773
end
771774
writer = RDF::Writer.for(meth.to_s[3..-1].to_sym) if meth.to_s[0,3] == "to_"

lib/rdf/model/statement.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,10 @@ def reified(subject: nil, id: nil, graph_name: nil)
426426
def method_missing(meth, *args)
427427
case meth
428428
when :to_hash
429-
warn "[DEPRECATION] Statement#to_hash is deprecated, use Statement#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
429+
warn "[DEPRECATION] RDF::Statement#to_hash is deprecated, use RDF::Statement#to_h instead.\n" +
430+
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
431+
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
432+
"Called from #{Gem.location_of_caller.join(':')}"
430433
self.to_h
431434
else
432435
super

lib/rdf/model/uri.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,10 @@ def format_authority
12991299
def method_missing(meth, *args)
13001300
case meth
13011301
when :to_hash
1302-
warn "[DEPRECATION] RDF::URI#to_hash is deprecated, use RDF::URI#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
1302+
warn "[DEPRECATION] RDF::URI#to_hash is deprecated, use RDF::URI#to_h instead.\n" +
1303+
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
1304+
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
1305+
"Called from #{Gem.location_of_caller.join(':')}"
13031306
self.to_h
13041307
else
13051308
super

lib/rdf/query/solution.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,10 @@ def inspect
277277
# @return [RDF::Term]
278278
def method_missing(name, *args, &block)
279279
if name == :to_hash
280-
warn "[DEPRECATION] Solution#to_hash is deprecated, use Solution#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
280+
warn "[DEPRECATION] RDF::Query::Solution#to_hash is deprecated, use RDF::Query::Solution#to_h instead.\n" +
281+
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
282+
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
283+
"Called from #{Gem.location_of_caller.join(':')}"
281284
self.to_h
282285
elsif args.empty? && @bindings.has_key?(name.to_sym)
283286
@bindings[name.to_sym]

lib/rdf/query/variable.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,10 @@ def to_s
229229
# @deprecated Use {#to_h} instead.
230230
def method_missing(name, *args, &block)
231231
if name == :to_hash
232-
warn "[DEPRECATION] Variable#to_hash is deprecated, use Variable#to_h instead. Called from #{Gem.location_of_caller.join(':')}"
232+
warn "[DEPRECATION] RDF::Query::Variable#to_hash is deprecated, use RDF::Query::Variable#to_h instead.\n" +
233+
"This is due to the introduction of keyword arugments that attempt to turn the last argument into a hash using #to_hash.\n" +
234+
"This can be avoided by explicitly passing an options hash as the last argument.\n" +
235+
"Called from #{Gem.location_of_caller.join(':')}"
233236
self.to_h
234237
elsif args.empty? && @bindings.has_key?(name.to_sym)
235238
@bindings[name.to_sym]

0 commit comments

Comments
 (0)