Class: Delfos::Patching::ModuleDefiner

Inherits:
Object
  • Object
show all
Defined in:
lib/delfos/patching/module_defining_methods.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, method_name, class_method) ⇒ ModuleDefiner

Returns a new instance of ModuleDefiner.



26
27
28
# File 'lib/delfos/patching/module_defining_methods.rb', line 26

def initialize(klass, method_name, class_method)
  @klass, @method_name, @class_method = klass, method_name, class_method
end

Instance Attribute Details

#class_methodObject (readonly)

Returns the value of attribute class_method.



24
25
26
# File 'lib/delfos/patching/module_defining_methods.rb', line 24

def class_method
  @class_method
end

#klassObject (readonly)

Returns the value of attribute klass.



24
25
26
# File 'lib/delfos/patching/module_defining_methods.rb', line 24

def klass
  @klass
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



24
25
26
# File 'lib/delfos/patching/module_defining_methods.rb', line 24

def method_name
  @method_name
end

Instance Method Details

#perform(&block) ⇒ Object



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

def perform(&block)
  safe_method_name = safe_method_name()
  safe_class_name = safe_class_name()
  module_type = class_method ? "ClassMethodLogging" : "InstanceMethodLogging"
  find_or_create = method(:find_or_create)

  m = nil
  Patching.const_get(module_type).instance_eval do
    namespace = find_or_create.call(self, safe_class_name)

    m = find_or_create.call(namespace, safe_method_name)

    m.class_eval(&block) if block_given?

    m
  end
end