Module: MarkMapper::Plugins::Document

Extended by:
ActiveSupport::Concern
Included in:
Document
Defined in:
lib/mark_mapper/plugins/document.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_root_documentObject

Used by embedded docs to find root easily without if/respond_to? stuff. Documents are always root documents.


36
37
38
# File 'lib/mark_mapper/plugins/document.rb', line 36

def _root_document
  self
end

#destroyed?Boolean

Returns:


17
18
19
# File 'lib/mark_mapper/plugins/document.rb', line 17

def destroyed?
  !!(@_destroyed ||= false)
end

#new?Boolean

Returns:


13
14
15
# File 'lib/mark_mapper/plugins/document.rb', line 13

def new?
  !!(@_new ||= false)
end

#reloadObject


21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mark_mapper/plugins/document.rb', line 21

def reload
  if doc = collection.find_one(:_id => id)
    self.class.associations.each_value do |association|
      get_proxy(association).reset
    end
    instance_variables.each { |ivar| remove_instance_variable(ivar) }
    initialize_from_database(doc)
    self
  else
    raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection"
  end
end