1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
module Clockwork
module DatabaseEvents
class EventCollection
def initialize(manager=Clockwork.manager)
@events = []
@manager = manager
end
def add(event)
@events << event
end
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
def unregister
events.each{|e| manager.unregister(e) }
end
private
attr_reader :events, :manager
# All events in the same collection (for a model instance) are equivalent
# so we can use any of them. Only their @at variable will be different,
# but we don't care about that here.
def event
events.first
end
end
end
end
|