Sha256: 6c825474c39a9046be0e226d5b0d4c56f986f003461ba3c2a1911e3278f39d0e

Contents?: true

Size: 845 Bytes

Versions: 16

Compression:

Stored size: 845 Bytes

Contents

module Restly::Associations::Base::Builders

  # Build
  def build(parent, attributes = nil, options = {})

    # Merge Options
    options.reverse_merge!(self.options)

    # Authorize and Set Path
    association = authorize(options[:authorize]).with_path(parent, options[:path])

    collection? ? association.build_collection(parent) : association.build_instance(parent, attributes)
  end

  def build_instance(parent, attributes)
    instance = association_class.new(attributes, options)
    instance.write_attribute("#{@owner.resource_name}_id", parent.id) if association_class.method_defined?("#{@owner.resource_name}_id")
    Restly::Proxies::Associations::Instance.new(instance, parent)
  end

  def build_collection(parent)
    Restly::Proxies::Associations::Collection.new(Restly::Collection.new(association_class), parent)
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

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