Sha256: 20a644efd07e3593ab005b6c1a27ac49ea942f9fce6bcacc15fdc06788bd06ad

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 KB

Contents

module Restly::EmbeddedAssociations::ClassMethods

  private

  # Embeds One
  def embeds_resource(name, options = {})
    exclude_field(name) if ancestors.include?(Restly::Base)
    self.resource_associations[name] = association = EmbedsOne.new(self, name, options)

    define_method name do |options={}|
      return get_association(name) if get_association(name).present?
      set_association name, association.stub(self)
    end

    define_method "#{name}=" do |value|
      set_association name, value
    end

  end

  # Embeds Many
  def embeds_resources(name, options = {})
    exclude_field(name) if ancestors.include?(Restly::Base)
    self.resource_associations[name] = association = EmbedsMany.new(self, name, options)

    define_method name do |options={}|
      get_association(name, options)
    end

    define_method "#{name}=" do |value|
      set_association name, value
    end

  end

  def embedded_in(name, options={})
    self.resource_associations[name] = association = EmbeddedIn.new(self, name, options)

    define_method name do |options={}|
      get_association(name, options)
    end

    define_method "#{name}=" do |value|
      set_association name, value
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
restly-0.0.1.alpha.8 lib/restly/embedded_associations/class_methods.rb
restly-0.0.1.alpha.7 lib/restly/embedded_associations/class_methods.rb
restly-0.0.1.alpha.6 lib/restly/embedded_associations/class_methods.rb