module Ork::Model::Embedded::ClassMethods

Attributes

__parent_key[RW]

Public Instance Methods

embedded(name, model) click to toggle source

Declares parent accessors for embedded objects and set the parent key

Example:

class Comment
  include Ork::Embeddable

  embedded :post, :Post
end

# It's the same as:

class Comment
  include Ork::Embeddable

  def post
    @attributes[:post]
  end

  def post=(post)
    @attributes[:post] = post
  end
end
# File lib/ork/model/class_methods.rb, line 175
def embedded(name, model)
  @__parent_key = name

  define_method(name) do
    @attributes[name]
  end

  define_method(:"#{name}=") do |object|
    raise Ork::ParentMissing if object.nil?

    @attributes[name] = object
  end
end