Class: Wallaby::Deprecator

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/wallaby/deprecator.rb

Overview

Deprecation log for methods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#alternativeMethod

Returns:

  • (Method)


19
20
21
# File 'lib/wallaby/deprecator.rb', line 19

def alternative
  @alternative
end

#fromString

Returns:

  • (String)


13
14
15
# File 'lib/wallaby/deprecator.rb', line 13

def from
  @from
end

#method_instanceMethod

Returns:

  • (Method)


10
11
12
# File 'lib/wallaby/deprecator.rb', line 10

def method_instance
  @method_instance
end

#modClass

Returns:

  • (Class)


16
17
18
# File 'lib/wallaby/deprecator.rb', line 16

def mod
  @mod
end

Class Method Details

.alert(method_instance, from:, mod: Core, alternative: nil) ⇒ Object

Log an warning deprecation message or raise MethodRemoved when the given method is obsolete.

Parameters:

  • method_instance (Method)

    deprecated/obsolete method

  • from (String)

    from/since version

  • mod (Class) (defaults to: Core)

    class name which has ‘VERSION` constants

  • alternative (Method) (defaults to: nil)

    method to replace the deprecated/obsolete one

See Also:



27
28
29
30
31
# File 'lib/wallaby/deprecator.rb', line 27

def self.alert(method_instance, from:, mod: Core, alternative: nil)
  new(
    method_instance: method_instance, from: from, mod: mod, alternative: alternative
  ).alert
end

Instance Method Details

#alertObject

Raises:



34
35
36
37
38
39
40
# File 'lib/wallaby/deprecator.rb', line 34

def alert
  # if current version is larger than from version
  already = Gem::Version.new(mod_version) >= Gem::Version.new(from)
  raise MethodRemoved, obsolete_message if already

  Logger.warn deprecated_message, sourcing: 2
end