Module: Ork::Model::Embedded::ClassMethods
- Defined in:
- lib/ork/model/class_methods.rb
Instance Attribute Summary collapse
-
#__parent_key ⇒ Object
Returns the value of attribute __parent_key.
Instance Method Summary collapse
-
#embedded(name, model) ⇒ Object
Declares parent accessors for embedded objects and set the parent key.
Instance Attribute Details
#__parent_key ⇒ Object
Returns the value of attribute __parent_key.
150 151 152 |
# File 'lib/ork/model/class_methods.rb', line 150 def __parent_key @__parent_key end |
Instance Method Details
#embedded(name, model) ⇒ Object
Declares parent accessors for embedded objects and set the parent key
Example:
class Comment
include Ork::Embeddable
: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
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ork/model/class_methods.rb', line 175 def (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 |