Module: DeprecateSoft

Defined in:
lib/deprecate_soft.rb,
lib/deprecate_soft/version.rb,
lib/deprecate_soft/method_wrapper.rb,
lib/deprecate_soft/global_monkey_patch.rb

Defined Under Namespace

Modules: ClassMethods, GlobalMonkeyPatch, MethodWrapper

Constant Summary collapse

VERSION =
'1.2.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.after_hookObject

Returns the value of attribute after_hook.



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

def after_hook
  @after_hook
end

.before_hookObject

Returns the value of attribute before_hook.



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

def before_hook
  @before_hook
end

.prefixObject



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

def prefix
  @prefix || '__'
end

.suffixObject



17
18
19
# File 'lib/deprecate_soft.rb', line 17

def suffix
  @suffix || 'deprecated'
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (DeprecateSoft)

    the object that the method was called on



21
22
23
# File 'lib/deprecate_soft.rb', line 21

def configure
  yield self
end

.included(base) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/deprecate_soft.rb', line 29

def included(base)
  base.extend(ClassMethods)

  base.define_singleton_method(:method_added) do |method_name|
    pending = base.instance_variable_get(:@__pending_soft_wraps)
    if pending&.key?(method_name)
      DeprecateSoft::MethodWrapper.wrap_method(base, method_name, pending.delete(method_name), is_class_method: false)
    end
    super(method_name) if defined?(super)
  end

  base.singleton_class.define_method(:singleton_method_added) do |method_name|
    pending = instance_variable_get(:@_pending_soft_wraps)
    if pending&.key?(method_name)
      DeprecateSoft::MethodWrapper.wrap_method(base, method_name, pending.delete(method_name), is_class_method: true)
    end
    super(method_name) if defined?(super)
  end
end

.prefixed_name(method_name) ⇒ Object



25
26
27
# File 'lib/deprecate_soft.rb', line 25

def prefixed_name(method_name)
  "#{prefix}#{method_name}_#{suffix}".to_sym
end