Class: EventProcessor
- Inherits:
-
Object
- Object
- EventProcessor
- Defined in:
- lib/ObjectModel/Repository/EventProcessor.rb
Instance Method Summary collapse
- #fire_after(entity, event, *params) ⇒ Object
- #fire_after_commit ⇒ Object
- #fire_before(entity, event, *params) ⇒ Object
- #fire_before_commit ⇒ Object
-
#initialize(transaction) ⇒ EventProcessor
constructor
A new instance of EventProcessor.
Constructor Details
#initialize(transaction) ⇒ EventProcessor
Returns a new instance of EventProcessor.
2 3 4 5 |
# File 'lib/ObjectModel/Repository/EventProcessor.rb', line 2 def initialize transaction @transaction = transaction @before_history = [] end |
Instance Method Details
#fire_after(entity, event, *params) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ObjectModel/Repository/EventProcessor.rb', line 18 def fire_after entity, event, *params entity.should! :be_a, Entity event.should! :be_in, Metadata::AFTER_EVENT_TYPES l_event = :"after_#{event}" @transaction.repository.entity_listeners.each{|l| l.respond_to l_event, entity, *params} @transaction.system_listener.respond_to l_event, entity, *params entity..after.fire entity, event, *params end |
#fire_after_commit ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ObjectModel/Repository/EventProcessor.rb', line 41 def fire_after_commit entities = [] @transaction.copies.each do |entity_id, c| entity = if @transaction.deleted_entities.include? entity_id @transaction.deleted_entities[entity_id] else @transaction.repository.by_id entity_id end entities << entity end # :after_commit @transaction.repository.entity_listeners.each{|l| l.respond_to :after_commit, entities} @transaction.system_listener.respond_to :after_commit, entities entities.each{|e| e..after.fire e, :commit} end |
#fire_before(entity, event, *params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ObjectModel/Repository/EventProcessor.rb', line 7 def fire_before entity, event, *params entity.should! :be_a, Entity event.should! :be_in, Metadata::BEFORE_EVENT_TYPES l_event = :"before_#{event}" @transaction.repository.entity_listeners.each{|l| l.respond_to l_event, entity, *params} @transaction.system_listener.respond_to l_event, entity, *params entity..before.fire entity, event, *params end |
#fire_before_commit ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ObjectModel/Repository/EventProcessor.rb', line 29 def fire_before_commit entities = [] @transaction.copies.each do |entity_id, c| entities << @transaction.resolve(entity_id) end @transaction.repository.entity_listeners.each{|l| l.respond_to :before_commit, entities} @transaction.system_listener.respond_to :before_commit, entities entities.each{|e| e..before.fire e, :commit} end |