Module: Sqreen::Deprecation

Includes:
Log::Loggable
Defined in:
lib/sqreen/deprecation.rb

Class Method Summary collapse

Methods included from Log::Loggable

included, #logger

Class Method Details

.deprecate(method) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sqreen/deprecation.rb', line 14

def deprecate(method)
  return unless ENV['SQREEN_DEBUG_DEPRECATION']

  owner = method.owner
  deprecated = :"_deprecated_#{method.name}"
  klass = owner.is_a?(Module)
  target = klass ? owner.to_s : owner.class.to_s

  method.owner.instance_eval do
    alias_method deprecated, method.name

    define_method(method.name) do |*args, &block|
      msg = [
        "deprecation",
        "target:#{target}",
        "method:#{method.name}",
        "caller:#{Kernel.caller_locations[0]}",
      ].join(' ')
      Sqreen::Deprecation.logger.info(msg)
      send(deprecated, *args, &block)
    end
  end
end