Class: Symbiont::Isolator
- Inherits:
-
Object
- Object
- Symbiont::Isolator
- Defined in:
- lib/symbiont/isolator.rb
Overview
Special object that wraps your proc object from any place and provides an ability to invoke this proc object lazily inside an any series of contexts.
Constant Summary collapse
- UnprovidedClosureAttributeError =
Is raised when closure is not provided.
Class.new(ArgumentError)
Instance Attribute Summary collapse
-
#closure ⇒ Proc
readonly
Proc object that will be evaluated in many contexts: initial, outer and kernel.
-
#default_direction ⇒ Array<Symbol>
readonly
An array of symbols that represents the direction of contexts.
Instance Method Summary collapse
-
#evaluate(*required_contexts, direction: default_direction) ⇒ void
Starts execution of a proc object in the context of the passed object with the selected direction of method dispatching.
-
#evaluate_private(*required_contexts, direction: default_direction) ⇒ void
Starts execution of a proc object in the context of the passed object with the selected direction of method dispatching.
-
#initialize(default_direction: Trigger::IOK, &closure) ⇒ Isolator
constructor
Instantiates isolator object with corresponding default direction and closure.
-
#private_method(method_name, *required_contexts, direction: default_direction) ⇒ Method
Gets the method object taken from the context that can respond to it.
-
#private_trigger(*required_contexts, direction: default_direction) ⇒ Symbiont::PrivateTrigger
private
private
Factory method that instantiates a private trigger with the desired execution context, the direction of method dispatching and the closure that needs to be performed.
-
#public_method(method_name, *required_contexts, direction: default_direction) ⇒ Method
Gets the method object taken from the context that can respond to it.
-
#public_trigger(*required_contexts, direction: default_direction) ⇒ Symbiont::PublicTrigger
private
private
Factory method that instantiates a public trigger with the desired execution context, the direction of method dispatching and the closure that needs to be performed.
Constructor Details
#initialize(default_direction: Trigger::IOK, &closure) ⇒ Isolator
Instantiates isolator object with corresponding default direction and closure.
46 47 48 49 50 51 |
# File 'lib/symbiont/isolator.rb', line 46 def initialize(default_direction: Trigger::IOK, &closure) raise UnprovidedClosureAttributeError, 'You should provide a closure' unless block_given? @default_direction = default_direction @closure = closure end |
Instance Attribute Details
#closure ⇒ Proc (readonly)
Proc object that will be evaluated in many contexts: initial, outer and kernel. Will be used as an outer-context for the method resolution.
25 26 27 |
# File 'lib/symbiont/isolator.rb', line 25 def closure @closure end |
#default_direction ⇒ Array<Symbol> (readonly)
An array of symbols that represents the direction of contexts. Used by default.
33 34 35 |
# File 'lib/symbiont/isolator.rb', line 33 def default_direction @default_direction end |
Instance Method Details
#evaluate(*required_contexts, direction: default_direction) ⇒ void
This method returns an undefined value.
Starts execution of a proc object in the context of the passed object with the selected direction of method dispatching. Delegates execution to a public trigger.
68 69 70 |
# File 'lib/symbiont/isolator.rb', line 68 def evaluate(*required_contexts, direction: default_direction) public_trigger(*required_contexts, direction: direction).__evaluate__ end |
#evaluate_private(*required_contexts, direction: default_direction) ⇒ void
This method returns an undefined value.
Starts execution of a proc object in the context of the passed object with the selected direction of method dispatching. Delegates execution to a private trigger.
87 88 89 |
# File 'lib/symbiont/isolator.rb', line 87 def evaluate_private(*required_contexts, direction: default_direction) private_trigger(*required_contexts, direction: direction).__evaluate__ end |
#private_method(method_name, *required_contexts, direction: default_direction) ⇒ Method
Gets the method object taken from the context that can respond to it. Considers private methods and public methods.
127 128 129 |
# File 'lib/symbiont/isolator.rb', line 127 def private_method(method_name, *required_contexts, direction: default_direction) private_trigger(*required_contexts, direction: direction).method(method_name) end |
#private_trigger(*required_contexts, direction: default_direction) ⇒ Symbiont::PrivateTrigger (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Factory method that instantiates a private trigger with the desired execution context, the direction of method dispatching and the closure that needs to be performed.
181 182 183 |
# File 'lib/symbiont/isolator.rb', line 181 def private_trigger(*required_contexts, direction: default_direction) PrivateTrigger.new(*required_contexts, context_direction: direction, &closure) end |
#public_method(method_name, *required_contexts, direction: default_direction) ⇒ Method
Gets the method object taken from the context that can respond to it. Considers only public methods.
107 108 109 |
# File 'lib/symbiont/isolator.rb', line 107 def public_method(method_name, *required_contexts, direction: default_direction) public_trigger(*required_contexts, direction: direction).method(method_name) end |
#public_trigger(*required_contexts, direction: default_direction) ⇒ Symbiont::PublicTrigger (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Factory method that instantiates a public trigger with the desired execution context, the direction of method dispatching and the closure that needs to be performed.
155 156 157 |
# File 'lib/symbiont/isolator.rb', line 155 def public_trigger(*required_contexts, direction: default_direction) PublicTrigger.new(*required_contexts, context_direction: direction, &closure) end |