Class: Satchel::ContextBuilder
- Inherits:
-
Object
- Object
- Satchel::ContextBuilder
- Defined in:
- lib/satchel/context_builder.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
writeonly
Sets the attribute class_name.
-
#context_class ⇒ Object
Returns the value of attribute context_class.
-
#context_method ⇒ Object
Returns the value of attribute context_method.
-
#method_name ⇒ Object
writeonly
Sets the attribute method_name.
Instance Method Summary collapse
-
#initialize(class_name, method_name) ⇒ ContextBuilder
constructor
A new instance of ContextBuilder.
- #wrap!(wrapper) ⇒ Object
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
24 25 26 |
# File 'lib/satchel/context_builder.rb', line 24 def class_name=(value) @class_name = value end |
#context_class ⇒ Object
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_method ⇒ Object
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
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 |