Class: Clockwork::DatabaseEvents::EventCollection

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

Instance Method Summary collapse

Constructor Details

#initialize(manager = Clockwork.manager) ⇒ EventCollection

Returns a new instance of EventCollection.



5
6
7
8
# File 'lib/clockwork/database_events/event_collection.rb', line 5

def initialize(manager=Clockwork.manager)
  @events = []
  @manager = manager
end

Instance Method Details

#add(event) ⇒ Object



10
11
12
# File 'lib/clockwork/database_events/event_collection.rb', line 10

def add(event)
  @events << event
end

#has_changed?(model) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/clockwork/database_events/event_collection.rb', line 14

def has_changed?(model)
  return true if event.nil?

  ignored_attributes = model.ignored_attributes if model.respond_to?(:ignored_attributes)
  ignored_attributes ||= []

  model_attributes = model.attributes.select do |k, _|
    not ignored_attributes.include?(k.to_sym)
  end

  event.model_attributes != model_attributes
end

#unregisterObject



27
28
29
# File 'lib/clockwork/database_events/event_collection.rb', line 27

def unregister
  events.each{|e| manager.unregister(e) }
end