Skip to content

Commit

Permalink
Fix caller search
Browse files Browse the repository at this point in the history
Until now it pointed to the place where dry-core or its dependants were
required. This is clearly a bug
  • Loading branch information
flash-gordon committed Aug 31, 2017
1 parent d51f5a0 commit 469ebbe
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions lib/dry/core/deprecations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module Core
#
# @api public
module Deprecations
STACK = -> { caller.find { |l| l !~ %r{(lib/dry/core)|(gems)} } }

class << self
# Prints a warning
#
Expand All @@ -45,8 +47,8 @@ def announce(name, msg, tag: nil)
# @api private
def deprecation_message(name, msg)
<<-MSG
#{name} is deprecated and will be removed in the next major version
#{message(msg)}
#{ name } is deprecated and will be removed in the next major version
#{ msg }
MSG
end

Expand All @@ -62,14 +64,6 @@ def deprecated_method_message(old, new = nil, msg = nil)
end
end

# @api private
def message(msg)
<<-MSG
#{msg}
#{caller.detect { |l| l !~ %r{(lib/dry/core)|(gems)} }}
MSG
end

# Returns the logger used for printing warnings.
# You can provide your own with .set_logger!
#
Expand Down Expand Up @@ -159,7 +153,7 @@ def deprecate(old_name, new_name = nil, message: nil)
undef_method old_name if method_defined?(old_name)

define_method(old_name) do |*args, &block|
mod.warn(full_msg)
mod.warn("#{ full_msg }\n#{ STACK.() }")
__send__(new_name, *args, &block)
end
else
Expand All @@ -169,7 +163,7 @@ def deprecate(old_name, new_name = nil, message: nil)
undef_method old_name

define_method(old_name) do |*args, &block|
mod.warn(full_msg)
mod.warn("#{ full_msg }\n#{ STACK.() }")
__send__(aliased_name, *args, &block)
end
end
Expand All @@ -193,7 +187,7 @@ def deprecate_class_method(old_name, new_name = nil, message: nil)
undef_method old_name if method_defined?(old_name)

define_method(old_name) do |*args, &block|
warn(full_msg)
warn("#{ full_msg }\n#{ STACK.() }")
meth.call(*args, &block)
end
end
Expand Down

0 comments on commit 469ebbe

Please sign in to comment.