Sha256: c91f15ec0ee543403166ac6c3404445f6ead087f1f61d6670e7b61a67f0fe46f

Contents?: true

Size: 997 Bytes

Versions: 57

Compression:

Stored size: 997 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Document
      module ClassMethods
        def embeddable?
          false
        end
      end

      module InstanceMethods
        def new?
          @_new
        end

        def destroyed?
          @_destroyed == true
        end

        def reload
          if doc = collection.find_one(:_id => id)
            tap do |instance|
              instance.class.associations.each_key do |association_name|
                send(association_name).reset if respond_to?(association_name)
              end
              instance.attributes = doc
            end
          else
            raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
          end
        end

        # Used by embedded docs to find root easily without if/respond_to? stuff.
        # Documents are always root documents.
        def _root_document
          self
        end
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 6 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/document.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/document.rb
mongo_mapper-0.8.6 lib/mongo_mapper/plugins/document.rb
mongo_mapper-0.8.5 lib/mongo_mapper/plugins/document.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/plugins/document.rb
mongo_mapper-0.8.4 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/document.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.08 lib/mongo_mapper/plugins/document.rb
mongo_mapper-unstable-2010.08.06 lib/mongo_mapper/plugins/document.rb