class Patriarch::ToolServices::RedisCleanerService

Adding behaviours to classes through Patriarch induces writes in Redis Database What happens when we want to destroy an item is that it fires ActiveRecord::Callbacks to deal with this kind of stuff. We build a transaction item whose execute would clean redis stuff but do nothing until commit happens in case SQL aborts. This service takes care of building clean items

Public Instance Methods

clean_all(calling_entity,options={}) click to toggle source

@param [Object] calling_entity the entity calling the clean upon itself @param [Object] options various options we may want to pass, used here to transmit a transaction item if a clean transaction wraps all the clean @return [Patriarch::Transaction] returns a transaction item that is either built from scratch or was passed through options and has been completed

# File lib/patriarch/tool_services/redis_cleaner_service.rb, line 11
def clean_all(calling_entity,options={})
  transac = options[:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_all".to_sym)
  options = { :transac => transac }

  calling_entity.class.patriarch_behaviours.keys.each do |behaviour|
    transac.steps << clean_behaviour(calling_entity,behaviour)
  end

  transac
end
clean_behaviour(calling_entity,behaviour,options={}) click to toggle source

@return [Patriarch::Transaction] returns a transaction item that is either built from scratch or was passed through options and has been completed @param [Object] calling_entity the entity calling the clean upon itself @param [Object] behaviour the behaviour the entity wants to clean @param [Object] options various options we may want to pass, used here to transmit a transaction item if a clean transaction wraps all the clean behaviours so it runs once and not multiple transactions.

# File lib/patriarch/tool_services/redis_cleaner_service.rb, line 27
def clean_behaviour(calling_entity,behaviour,options={})
  my_behaviours = calling_entity.class.patriarch_behaviours
  behaviour_symbol = behaviour.to_s.underscore.to_sym

  if my_behaviours.include? behaviour_symbol
    if my_behaviours[behaviour_symbol].first.size == 3
      clean_tripartite_behaviour(calling_entity,behaviour,options)
    elsif my_behaviours[behaviour_symbol].first.size == 2
      clean_bipartite_behaviour(calling_entity,behaviour,options)
    else
      raise "Bad Behaviour declaration occured, no doublet or triplet are registered"
    end
  end
end