Class: Patriarch::TransactionStep
- Inherits:
-
Object
- Object
- Patriarch::TransactionStep
- Defined in:
- lib/patriarch/transaction_step.rb
Overview
Represents a “step” i.e. what should occur from no sql database point of view when a model instance invokes a behaviour. It is encapsulated into Patriarch::Transaction item and is never exposed. When needed, Patriarch::Transaction will forward some method call to the current TransactionStep that is being built
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
-
#actor ⇒ Object
The actor of this step.
- #add_to_queue(struct) ⇒ Object
-
#execute ⇒ Object
execute the redis instructions embedded into this step against instructions are a dao, a method to call upon and its argument embedded into a OpenStruct before Patriarch 0.2.5, was embedded directly in a proc, was a complete failure for unknown reasons Patriach::Transaction use this method on each of the steps it registered within a multi block.
-
#initialize(relation_type, actor, target, medium = nil) ⇒ TransactionStep
constructor
A new instance of TransactionStep.
-
#medium ⇒ Object
The medium of this step if it exists.
- #protagonists_models ⇒ Object
-
#target ⇒ Object
The target of this step.
Constructor Details
#initialize(relation_type, actor, target, medium = nil) ⇒ TransactionStep
Returns a new instance of TransactionStep.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/patriarch/transaction_step.rb', line 9 def initialize(relation_type,actor,target,medium = nil) @context = { :relation_type => relation_type, :actor_type => actor.class.name.underscore.to_sym, :target_type => target.class.name.underscore.to_sym, :actor_id => actor.id, :target_id => target.id, } if medium @context.merge! :medium_id => medium.id, :medium_type => medium.class.name.underscore.to_sym end @queue = [] end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
7 8 9 |
# File 'lib/patriarch/transaction_step.rb', line 7 def context @context end |
#queue ⇒ Object
Returns the value of attribute queue.
7 8 9 |
# File 'lib/patriarch/transaction_step.rb', line 7 def queue @queue end |
Instance Method Details
#actor ⇒ Object
Returns the actor of this step.
37 38 39 |
# File 'lib/patriarch/transaction_step.rb', line 37 def actor actor_type.to_s.camelize.constantize.find actor_id end |
#add_to_queue(struct) ⇒ Object
63 64 65 |
# File 'lib/patriarch/transaction_step.rb', line 63 def add_to_queue(struct) queue << struct end |
#execute ⇒ Object
execute the redis instructions embedded into this step against instructions are a dao, a method to call upon and its argument embedded into a OpenStruct before Patriarch 0.2.5, was embedded directly in a proc, was a complete failure for unknown reasons Patriach::Transaction use this method on each of the steps it registered within a multi block
56 57 58 59 60 |
# File 'lib/patriarch/transaction_step.rb', line 56 def execute queue.each do |redis_struct_instruction| redis_struct_instruction.execute end end |
#medium ⇒ Object
Returns the medium of this step if it exists.
31 32 33 34 |
# File 'lib/patriarch/transaction_step.rb', line 31 def medium return nil unless medium_id && medium_type medium_type.to_s.camelize.constantize.find medium_id end |
#protagonists_models ⇒ Object
46 47 48 49 50 |
# File 'lib/patriarch/transaction_step.rb', line 46 def protagonists_models # By convention always actor, target, model for tripartite and # actor, model for bipartite [actor,target,medium].compact.map(&:class) end |
#target ⇒ Object
Returns the target of this step.
42 43 44 |
# File 'lib/patriarch/transaction_step.rb', line 42 def target target_type.to_s.camelize.constantize.find target_id end |