Sha256: e705d10c8e024a4100039370c3099784b8b8d71aa3e1f7b82d04a68233d47a18

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

module MongoMapper
  module EmbeddedDocument
    extend 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::Rails
        plugin Plugins::Serialization
        plugin Plugins::Validations

        attr_accessor :_root_document
      end
      
      super
    end

    module ClassMethods
      def embeddable?
        true
      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

      def update_attributes(attrs={})
        self.attributes = attrs
        self.save
      end

      def update_attributes!(attrs={})
        self.attributes = attrs
        self.save!
      end
    end # InstanceMethods
  end # EmbeddedDocument
end # MongoMapper

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongo_mapper-unstable-2010.1.27 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.26 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.25 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.22 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.21 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.20 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.19 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.18 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.17 lib/mongo_mapper/embedded_document.rb
mongo_mapper-unstable-2010.1.12 lib/mongo_mapper/embedded_document.rb