Sha256: 6c93929f3b5b9ce7700f608de1d3e57941a673b5e26e0970e032a6e40054f607

Contents?: true

Size: 843 Bytes

Versions: 1

Compression:

Stored size: 843 Bytes

Contents

class ActivityObserver < ActiveRecord::Observer
  class << self
    # we don't want to include the activity model
    def observed_class
      nil
    end
  end
  
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
evilmarty_activity_stream-1.0.0 lib/activity_observer.rb