Sha256: 43d1e312dcd9ec4aeeede24f84b54025e956c197d7903ed35103ac8d1a435aec

Contents?: true

Size: 1.04 KB

Versions: 52

Compression:

Stored size: 1.04 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module EmbeddedDocument
      def self.configure(model)
        model.class_eval do
          attr_reader :_root_document, :_parent_document
        end
      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 _parent_document=(value)
          @_root_document   = value._root_document
          @_parent_document = value
        end
      end
    end
  end
end

Version data entries

52 entries across 52 versions & 3 rubygems

Version Path
mongo_mapper-unstable-2010.07.30 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.29 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.28 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.27 lib/mongo_mapper/plugins/embedded_document.rb
thorsson-mongo_mapper-0.8.2 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.26 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.23 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.21 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.20 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.19 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.18 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.16 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.15 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.14 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.13 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.12 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.09 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.08 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.07 lib/mongo_mapper/plugins/embedded_document.rb
mongo_mapper-unstable-2010.07.06 lib/mongo_mapper/plugins/embedded_document.rb