Sha256: bae6dd5453cca523cb25a5a9bada41761a9ab479d30d0ff7088347ce22d5aa0e

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 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::Protected
        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

7 entries across 7 versions & 1 rubygems

Version Path
jmonteiro-mongo_mapper-0.1.7 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.6 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.5 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.4 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.2 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.1 lib/mongo_mapper/embedded_document.rb
jmonteiro-mongo_mapper-0.1.0 lib/mongo_mapper/embedded_document.rb