Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (40 sloc) 1007 Bytes
# encoding: UTF-8
module MongoMapper
module Plugins
module EmbeddedDocument
extend ActiveSupport::Concern
included do
attr_accessor :_parent_document
end
module ClassMethods
def embeddable?
true
end
def embedded_in(owner_name)
define_method(owner_name) { _parent_document }
end
end
module InstanceMethods
def new?
_root_document.try(:new?) || @_new
end
def destroyed?
!!_root_document.try(:destroyed?)
end
def save(options={})
_root_document.try(:save, options).tap do |result|
@_new = false if result
end
end
def save!(options={})
_root_document.try(:save, options).tap do |result|
@_new = false if result
end
end
def _root_document
@_root_document ||= _parent_document.try(:_root_document)
end
end
end
end
end
Jump to Line
Something went wrong with that request. Please try again.