Class: Correlate::Relationships::ActiveRecord::CollectionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/correlate/relationships/active_record/collection_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(source, correlation) ⇒ CollectionProxy

Returns a new instance of CollectionProxy.



8
9
10
11
12
# File 'lib/correlate/relationships/active_record/collection_proxy.rb', line 8

def initialize( source, correlation )
  @source = source
  @correlation = correlation
  @collection = correlation.correlate( source )
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



26
27
28
# File 'lib/correlate/relationships/active_record/collection_proxy.rb', line 26

def method_missing( name, *args, &block )
  @collection.send( name, *args, &block )
end

Instance Method Details

#<<(object) ⇒ Object Also known as: push, concat



14
15
16
17
18
19
# File 'lib/correlate/relationships/active_record/collection_proxy.rb', line 14

def <<( object )
  correlation = @correlation.opposite

  object.send( "#{correlation.name}=", @source )
  object.save
end