class Patriarch::TransactionStep

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

Attributes

context[RW]
queue[RW]

Public Class Methods

new(relation_type,actor,target,medium = nil) click to toggle source
# 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

Public Instance Methods

actor() click to toggle source

@return the actor of this step

# File lib/patriarch/transaction_step.rb, line 37
def actor
  actor_type.to_s.camelize.constantize.find actor_id
end
add_to_queue(struct) click to toggle source

@param [Patriarch::RedisInstruction] ostruct dao with parameters and method to call embedded here to be processed later

# File lib/patriarch/transaction_step.rb, line 63
def add_to_queue(struct)
  queue << struct
end
execute() click to toggle source

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

# File lib/patriarch/transaction_step.rb, line 56
def execute
  queue.each do |redis_struct_instruction|
    redis_struct_instruction.execute
  end
end
medium() click to toggle source

@return the medium of this step if it exists

# 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() click to toggle source
# 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() click to toggle source

@return the target of this step

# File lib/patriarch/transaction_step.rb, line 42
def target
  target_type.to_s.camelize.constantize.find target_id
end