2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-10-14 21:45:58 +01:00
|
|
|
class EventLogObserver < ActiveRecord::Observer
|
2012-03-29 19:43:46 +01:00
|
|
|
observe :user, :private_user, :platform, :repository, :project, :product, :build_list, :product_build_list
|
2011-10-14 21:45:58 +01:00
|
|
|
|
|
|
|
def after_create(record)
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
|
2011-10-28 23:31:47 +01:00
|
|
|
def before_update(record)
|
2011-11-07 22:54:25 +00:00
|
|
|
case record.class.to_s
|
|
|
|
when 'BuildList'
|
2011-11-11 17:13:09 +00:00
|
|
|
if record.status_changed? and [BuildList::BUILD_CANCELED, BuildList::BUILD_PUBLISHED].include?(record.status)
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
|
2011-10-28 23:31:47 +01:00
|
|
|
end
|
2011-11-07 22:54:25 +00:00
|
|
|
when 'Platform'
|
|
|
|
if record.visibility_changed?
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument "event_log.observer", :eventable => record,
|
2011-11-07 22:54:25 +00:00
|
|
|
:message => I18n.t("activerecord.attributes.platform.visibility_types.#{record.visibility}")
|
|
|
|
end
|
2011-10-28 23:31:47 +01:00
|
|
|
end
|
|
|
|
end
|
2011-10-14 21:45:58 +01:00
|
|
|
|
|
|
|
def after_destroy(record)
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => record)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
end
|