123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- module HasActivityStreamLog
- extend ActiveSupport::Concern
- included do
- after_create :activity_stream_create
- after_update :activity_stream_update
- before_destroy :activity_stream_destroy
- end
- def activity_stream_create
- activity_stream_log('create', self['created_by_id'])
- true
- end
- def activity_stream_update
- return true if !saved_changes?
- ignored_attributes = self.class.instance_variable_get(:@activity_stream_attributes_ignored) || []
- ignored_attributes += %i[created_at updated_at created_by_id updated_by_id]
- log = false
- saved_changes.each_key do |key|
- next if ignored_attributes.include?(key.to_sym)
- log = true
- end
- return true if !log
- activity_stream_log('update', self['updated_by_id'])
- true
- end
- def activity_stream_destroy
- ActivityStream.remove(self.class.to_s, id)
- true
- end
-
- class_methods do
- def activity_stream_attributes_ignored(*attributes)
- @activity_stream_attributes_ignored = attributes
- end
- def activity_stream_permission(permission)
- @activity_stream_permission = permission
- end
- end
- end
|