module Dynamoid::IdentityMap::ClassMethods

Public Instance Methods

find_by_id(id, options = {}) click to toggle source

@private

Calls superclass method
# File lib/dynamoid/identity_map.rb, line 34
def find_by_id(id, options = {})
  return super if identity_map_off?

  key = id.to_s

  if range_key = options[:range_key]
    key += "::#{range_key}"
  end

  identity_map[key] || super
end
from_database(attrs = {}) click to toggle source

@private

Calls superclass method
# File lib/dynamoid/identity_map.rb, line 17
def from_database(attrs = {})
  return super if identity_map_off?

  key = identity_map_key(attrs)
  document = identity_map[key]

  if document.nil?
    document = super
    identity_map[key] = document
  else
    document.load(attrs)
  end

  document
end
identity_map() click to toggle source
# File lib/dynamoid/identity_map.rb, line 12
def identity_map
  @identity_map ||= {}
end
identity_map_key(attrs) click to toggle source

@private

# File lib/dynamoid/identity_map.rb, line 47
def identity_map_key(attrs)
  key = attrs[hash_key].to_s
  key += "::#{attrs[range_key]}" if range_key
  key
end
identity_map_off?() click to toggle source
# File lib/dynamoid/identity_map.rb, line 57
def identity_map_off?
  !identity_map_on?
end
identity_map_on?() click to toggle source
# File lib/dynamoid/identity_map.rb, line 53
def identity_map_on?
  Dynamoid::Config.identity_map
end