Class: Patriarch::ToolServices::RedisCleanerService
- Defined in:
- lib/patriarch/tool_services/redis_cleaner_service.rb
Overview
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
Instance Method Summary collapse
-
#clean_all(calling_entity, options = {}) ⇒ Patriarch::Transaction
Returns a transaction item that is either built from scratch or was passed through options and has been completed.
-
#clean_behaviour(calling_entity, behaviour, options = {}) ⇒ Patriarch::Transaction
behaviours so it runs once and not multiple transactions.
-
#clean_bipartite_behaviour(calling_entity, behaviour, options = {}) ⇒ Object
:nodoc:.
-
#clean_tripartite_behaviour(calling_entity, behaviour, options = {}) ⇒ Object
:nodoc:.
Instance Method Details
#clean_all(calling_entity, options = {}) ⇒ Patriarch::Transaction
Returns a transaction item that is either built from scratch or was passed through options and has been completed
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/patriarch/tool_services/redis_cleaner_service.rb', line 11 def clean_all(calling_entity,={}) transac = [:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_all".to_sym) = { :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 = {}) ⇒ Patriarch::Transaction
behaviours so it runs once and not multiple transactions.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/patriarch/tool_services/redis_cleaner_service.rb', line 27 def clean_behaviour(calling_entity,behaviour,={}) 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,) elsif my_behaviours[behaviour_symbol].first.size == 2 clean_bipartite_behaviour(calling_entity,behaviour,) else raise "Bad Behaviour declaration occured, no doublet or triplet are registered" end end end |
#clean_bipartite_behaviour(calling_entity, behaviour, options = {}) ⇒ Object
:nodoc:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/patriarch/tool_services/redis_cleaner_service.rb', line 61 def clean_bipartite_behaviour(calling_entity,behaviour,={}) my_class = calling_entity.class bipartite_behaviour = my_class.patriarch_behaviours[behaviour.to_s.underscore.to_sym] transac = [:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym) = { :transac => transac, :stop_execution => true} bipartite_behaviour.each do |protagonists| clean_bipartite_behaviour_for_actor(calling_entity,behaviour,protagonists,) if protagonists.first == my_class clean_bipartite_behaviour_for_target(calling_entity,behaviour,protagonists,) if protagonists.second == my_class end transac end |
#clean_tripartite_behaviour(calling_entity, behaviour, options = {}) ⇒ Object
:nodoc:
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/patriarch/tool_services/redis_cleaner_service.rb', line 44 def clean_tripartite_behaviour(calling_entity,behaviour,={}) my_class = calling_entity.class tripartite_behaviour = my_class.patriarch_behaviours[behaviour.to_s.underscore.to_sym] transac = [:transac] || Patriarch::TransactionServices::TransactionManagerService.instance.new_transaction("clean_#{behaviour.to_s}".to_sym) = { :transac => transac, :stop_execution => true} tripartite_behaviour.each do |protagonists| clean_tripartite_behaviour_for_actor(calling_entity,behaviour,protagonists,) if protagonists.first == my_class clean_tripartite_behaviour_for_target(calling_entity,behaviour,protagonists,) if protagonists.second == my_class clean_tripartite_behaviour_for_medium(calling_entity,behaviour,protagonists,) if protagonists.third == my_class end transac end |