Sha256: 6f121586a1646dcc43da164061ce5d6901ee3d98341ac571bccb96c15f1b8779

Contents?: true

Size: 691 Bytes

Versions: 19

Compression:

Stored size: 691 Bytes

Contents

class Restly::Proxies::Associations::Collection < Restly::Proxies::Base

  attr_reader :parent, :joiner

  def initialize(collection, parent, joiner=nil)
    collection.map!{ |instance| Restly::Proxies::Associations::Instance.new(instance, parent, joiner) }
    super(collection)
    @parent = parent
    @joiner = joiner
  end

  def <<(instance)
    collection = super
    instance = create(instance.attributes) unless instance.persisted?
    if joiner
      joiner.create("#{parent.resource_name}_id" => parent.id, "#{instance.resource_name}_id" => instance.id)
    elsif parent
      instance.update_attributes("#{parent.resource_name}_id" => parent.id)
    end
    collection
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
restly-0.0.1.beta.10 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.9 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.6 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.5 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.4 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.3 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.2 lib/restly/proxies/associations/collection.rb
restly-0.0.1.beta.1 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.22 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.19 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.18 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.16 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.12 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.11 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.10 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.9 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.8 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.7 lib/restly/proxies/associations/collection.rb
restly-0.0.1.alpha.6 lib/restly/proxies/associations/collection.rb