Class: Satchel::ContextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/satchel/context_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(class_name, method_name) ⇒ ContextBuilder

Returns a new instance of ContextBuilder.



5
6
7
8
9
10
# File 'lib/satchel/context_builder.rb', line 5

def initialize(class_name, method_name)
  self.class_name = class_name
  self.method_name = method_name
  extract_context_class!
  extract_method!
end

Instance Attribute Details

#class_name=(value) ⇒ Object

Sets the attribute class_name

Parameters:

  • value

    the value to set the attribute class_name to.



24
25
26
# File 'lib/satchel/context_builder.rb', line 24

def class_name=(value)
  @class_name = value
end

#context_classObject

Returns the value of attribute context_class.



24
25
26
# File 'lib/satchel/context_builder.rb', line 24

def context_class
  @context_class
end

#context_methodObject

Returns the value of attribute context_method.



24
25
26
# File 'lib/satchel/context_builder.rb', line 24

def context_method
  @context_method
end

#method_name=(value) ⇒ Object

Sets the attribute method_name

Parameters:

  • value

    the value to set the attribute method_name to.



24
25
26
# File 'lib/satchel/context_builder.rb', line 24

def method_name=(value)
  @method_name = value
end

Instance Method Details

#wrap!(wrapper) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/satchel/context_builder.rb', line 12

def wrap!(wrapper)
  # Why the i prefix? We need the local variables to be availabe
  # within the context of the module_exec.
  context_class.module_exec(method_name, context_method, wrapper) { |imethod_name, icontext_method, wrapper_proc|
    define_method(imethod_name) { |*args, &block|
      returning_value = icontext_method.bind(self).call(*args, &block)
      wrapper_proc.call(self)
      returning_value
    }
  }
end