Class: Clockwork::DatabaseEvents::EventStore
- Inherits:
-
Object
- Object
- Clockwork::DatabaseEvents::EventStore
- Defined in:
- lib/clockwork/database_events/event_store.rb
Instance Method Summary collapse
-
#initialize(block_to_perform_on_event_trigger) ⇒ EventStore
constructor
A new instance of EventStore.
-
#register(event, model) ⇒ Object
DatabaseEvents::Manager#register creates a new DatabaseEvents::Event, whose #initialize method registers the new database event with the EventStore by calling this method.
- #register_new_models(model_objects) ⇒ Object
- #unregister_all_except(model_objects) ⇒ Object
- #update(current_model_objects) ⇒ Object
- #update_registered_models(model_objects) ⇒ Object
Constructor Details
#initialize(block_to_perform_on_event_trigger) ⇒ EventStore
Returns a new instance of EventStore.
32 33 34 35 |
# File 'lib/clockwork/database_events/event_store.rb', line 32 def initialize(block_to_perform_on_event_trigger) @related_events = {} @block_to_perform_on_event_trigger = block_to_perform_on_event_trigger end |
Instance Method Details
#register(event, model) ⇒ Object
DatabaseEvents::Manager#register creates a new DatabaseEvents::Event, whose #initialize method registers the new database event with the EventStore by calling this method.
40 41 42 |
# File 'lib/clockwork/database_events/event_store.rb', line 40 def register(event, model) (model.id).add(event) end |
#register_new_models(model_objects) ⇒ Object
64 65 66 67 68 |
# File 'lib/clockwork/database_events/event_store.rb', line 64 def register_new_models(model_objects) unregistered_models(model_objects).each do |new_model_object| register_with_manager(new_model_object) end end |
#unregister_all_except(model_objects) ⇒ Object
50 51 52 53 |
# File 'lib/clockwork/database_events/event_store.rb', line 50 def unregister_all_except(model_objects) ids = model_objects.collect(&:id) (@related_events.keys - ids).each{|id| unregister(id) } end |
#update(current_model_objects) ⇒ Object
44 45 46 47 48 |
# File 'lib/clockwork/database_events/event_store.rb', line 44 def update(current_model_objects) unregister_all_except(current_model_objects) update_registered_models(current_model_objects) register_new_models(current_model_objects) end |
#update_registered_models(model_objects) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/clockwork/database_events/event_store.rb', line 55 def update_registered_models(model_objects) registered_models(model_objects).each do |model| if has_changed?(model) unregister(model.id) register_with_manager(model) end end end |