Class: Clockwork::DatabaseEvents::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/clockwork/database_events/registry.rb

Instance Method Summary collapse

Constructor Details

#initializeRegistry


7
8
9
# File 'lib/clockwork/database_events/registry.rb', line 7

def initialize
  @events = Hash.new []
end

Instance Method Details

#event_for(model) ⇒ Object

all events of same id will have same frequency/name, just different ats


29
30
31
# File 'lib/clockwork/database_events/registry.rb', line 29

def event_for(model)
  events_for(model).first
end

#events_for(model) ⇒ Object


33
34
35
# File 'lib/clockwork/database_events/registry.rb', line 33

def events_for(model)
  @events[model.id]
end

#register(event, model) ⇒ Object


11
12
13
# File 'lib/clockwork/database_events/registry.rb', line 11

def register(event, model)
  @events[model.id] = @events[model.id] + [event]
end

#unregister(model) ⇒ Object


15
16
17
# File 'lib/clockwork/database_events/registry.rb', line 15

def unregister(model)
  unregister_by_id(model.id)
end

#unregister_all_except(ids) ⇒ Object


24
25
26
# File 'lib/clockwork/database_events/registry.rb', line 24

def unregister_all_except(ids)
  (@events.keys - ids).each{|id| unregister_by_id(id) }
end

#unregister_by_id(id) ⇒ Object


19
20
21
22
# File 'lib/clockwork/database_events/registry.rb', line 19

def unregister_by_id(id)
  @events[id].each{|e| Clockwork.manager.unregister(e) }
  @events.delete(id)
end