Sha256: f2595a499383e2905bef4991c3d832f807ffb0fc3dbbbd93563f33c9da2a82dc
Contents?: true
Size: 1.1 KB
Versions: 6
Compression:
Stored size: 1.1 KB
Contents
# 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) alias_method owner_name, :_parent_document end end 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| persist(options) if result end end def save!(options={}) valid? || raise(DocumentNotValid.new(self)) _root_document.try(:save!, options).tap do |result| persist(options) if result end end def persist(options={}) @_new = false changes_applied if respond_to?(:changes_applied) save_to_collection(options) end def _root_document _parent_document.try(:_root_document) end end end end
Version data entries
6 entries across 6 versions & 1 rubygems