Module: ActivityStream::AssociationProxy

Defined in:
lib/activity_stream.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/activity_stream.rb', line 98

def self.included(base)
  base.class_eval do
    private
    def find_indirect_object
      # we don't want activity to be our indirect object
      return nil if @owner.class == Activity

      # tried to use memoize but too many errors, bah!
      @indirect_object ||= if @owner.class.respond_to?(:activity_triggers)
        @owner
      elsif ivar = @owner.instance_variable_get('@_indirect_object')
        ivar
      else
        nil
      end
    end

    def tag_with_indirect_object(record)
      record.instance_variable_set '@_indirect_object', find_indirect_object if find_indirect_object
    end
    
    def set_belongs_to_association_for_with_indirect_object(record)
      tag_with_indirect_object record
      set_belongs_to_association_for_without_indirect_object record
    end
    alias_method_chain :set_belongs_to_association_for, :indirect_object
  end
end