Class: ActivityObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
lib/activity_observer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.observed_classObject

we don’t want to include the activity model



4
5
6
# File 'lib/activity_observer.rb', line 4

def observed_class
  nil
end

Instance Method Details

#update(observed_method, object) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/activity_observer.rb', line 9

def update(observed_method, object)
  # check the object isn't an activity
  return if object.is_a? Activity
  context, block = Thread.current[:activity_stream_context], object.class.activity_triggers[observed_method]
  # lets not log an activity if we don't have an actor or isn't an allowed callback
  return unless !!context and (block.is_a?(Proc) ? block.call(object) != false : block == true)
  
  verb = observed_method.to_s.gsub /^after_/, ''
  
  attributes = context.attributes.merge :verb => verb, :object => object
  attributes[:indirect_object] ||= object.instance_variable_get('@_indirect_object')
  
  Activity.create(attributes)
end