Module: ActivityStream::HasOneAssociation

Defined in:
lib/activity_stream.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/activity_stream.rb', line 156

def self.included(base)
  base.class_eval do
    def replace_with_indirect_object(*args)
      tag_with_indirect_object args.first
      replace_without_indirect_object *args
    end
    alias_method_chain :replace, :indirect_object
    
    def new_record_with_indirect_object(replace_existing, &block)
      new_record_without_indirect_object replace_existing do |reflection|
        record = block.call reflection
        # if we are going to replace_existing, this'll get done in our 
        # replace_with_parental_control above - no point in doing it twice
        tag_with_indirect_object record unless replace_existing
        record
      end
    end
    alias_method_chain :new_record, :indirect_object

    def find_target_with_indirect_object
      record = find_target_without_indirect_object
      tag_with_indirect_object record
      record
    end
    alias_method_chain :find_target, :indirect_object
  end
end