Module: MarkMapperMethods::ClassMethods

Extended by:
ActiveSupport::Concern
Defined in:
lib/mark_mapper/plugins/identity_map.rb

Instance Method Summary collapse

Instance Method Details

#find_each(opts = {}) ⇒ Object


134
135
136
137
138
139
140
# File 'lib/mark_mapper/plugins/identity_map.rb', line 134

def find_each(opts={})
  query = clone.amend(opts)
  super(opts) do |doc|
    doc.remove_from_identity_map if doc && query.fields?
    yield doc if block_given?
  end
end

#find_one(opts = {}) ⇒ Object


122
123
124
125
126
127
128
129
130
131
132
# File 'lib/mark_mapper/plugins/identity_map.rb', line 122

def find_one(opts={})
  query = clone.amend(opts)

  if identity_map && query.simple? && (document = identity_map.get_from_identity_map(query[:_id]))
    document
  else
    super.tap do |doc|
      doc.remove_from_identity_map if doc && query.fields?
    end
  end
end