Add 'revision' attribute to Conference, managed by an observer

This commit is contained in:
Ancor Gonzalez Sosa 2013-07-08 10:03:03 +02:00
parent 27017a4823
commit d648ab7cb5
4 changed files with 34 additions and 1 deletions

View file

@ -0,0 +1,26 @@
#
# suseconferenceclient relies on a 'revision' attribute for caching and
# doing some calculations.
#
# It should be incremented after any change in the conference or in any
# associated models
#
# This observer updates the revision column in a non-intrusive way,
# preventing validations, callbacks or exceptions to be triggered
#
# Relying on paper_trail could also be an option, but a 'revision' column
# in table 'conferences' looks like a more simple and straightforward solution
#
class RevisionObserver < ActiveRecord::Observer
observe :conference, :event, :room, :social_event, :track
def after_save(model)
begin
conference = model.kind_of?(Conference) ? model : model.conference
conference.reload.increment(:revision)
conference.update_column(:revision, conference.revision)
rescue
nil
end
end
end