Class: Dry::Monads::Do::All::MethodTracker

Inherits:
Module
  • Object
show all
Defined in:
lib/dry/monads/do/all.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(wrappers) ⇒ MethodTracker

Returns a new instance of MethodTracker.


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/dry/monads/do/all.rb', line 62

def initialize(wrappers)
  super()

  @wrappers = wrappers
  tracker = self

  module_eval do
    define_method(:method_added) do |method|
      super(method)

      tracker.wrap_method(self, method)
    end

    define_method(:inherited) do |base|
      super(base)

      base.prepend(wrappers[base])
    end
  end
end

Instance Attribute Details

#wrappersObject (readonly)


60
61
62
# File 'lib/dry/monads/do/all.rb', line 60

def wrappers
  @wrappers
end

Instance Method Details

#extend_object(target) ⇒ Object


83
84
85
86
# File 'lib/dry/monads/do/all.rb', line 83

def extend_object(target)
  super
  target.prepend(wrappers[target])
end

#wrap_method(target, method) ⇒ Object


88
89
90
# File 'lib/dry/monads/do/all.rb', line 88

def wrap_method(target, method)
  Do.wrap_method(wrappers[target], method)
end