Sha256: 903d1db68153ae74eb34fbe0a7e6da1423c34d1865c55b9c0da31aaff3ec231e

Contents?: true

Size: 1.21 KB

Versions: 20

Compression:

Stored size: 1.21 KB

Contents

module MongoMapper
  module EmbeddedDocument
    extend Support::DescendantAppends

    def self.included(model)
      model.class_eval do
        include InstanceMethods
        extend  ClassMethods
        extend  Plugins

        plugin Plugins::Associations
        plugin Plugins::Clone
        plugin Plugins::Descendants
        plugin Plugins::Equality
        plugin Plugins::Inspect
        plugin Plugins::Keys
        plugin Plugins::Logger
        plugin Plugins::Protected
        plugin Plugins::Rails
        plugin Plugins::Serialization
        plugin Plugins::Validations

        attr_accessor :_root_document, :_parent_document
      end

      super
    end

    module ClassMethods
      def embeddable?
        true
      end

      def embedded_in(owner_name)
        define_method(owner_name) { _parent_document }
      end
    end

    module InstanceMethods
      def save(options={})
        if result = _root_document.try(:save, options)
          @new = false
        end
        result
      end

      def save!(options={})
        if result = _root_document.try(:save!, options)
          @new = false
        end
        result
      end
    end # InstanceMethods
  end # EmbeddedDocument
end # MongoMapper

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.27 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.26 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.25 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.24 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.23 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.22 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.19 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.18 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.17 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.16 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.15 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.12 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.11 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.10 lib/mongo_mapper/embedded_document.rb
mongo_mapper-0.7.0 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/embedded_document.rb