class EmpireAvenue::Identity

Public Class Methods

fetch(attrs) { || ... } click to toggle source
# File lib/empireavenue/identity.rb, line 7
def self.fetch(attrs)
  return unless identity_map

  id = attrs[:id]
  if id  && object = identity_map.fetch(id)
    return object.update(attrs)
  end

  return yield if block_given?
  raise EmpireAvenue::Error::IdentityMapKeyError, "key not found"
end
new(attrs={}) click to toggle source

Initializes a new object

@param attrs [Hash] @raise [ArgumentError] Error raised when supplied argument is missing an :id key. @return [EmpireAvenue::Identity]

Calls superclass method EmpireAvenue::Base::new
# File lib/empireavenue/identity.rb, line 33
def initialize(attrs={})
  attrs[:id] = attrs[:ticker] unless attrs[:id]
  super
  raise ArgumentError, "argument must have an :id key" unless id
end
store(object) click to toggle source

Stores an object in the identity map.

@param object [Object] @return [EmpireAvenue::Identity]

# File lib/empireavenue/identity.rb, line 23
def self.store(object)
  return object unless identity_map
  identity_map.store(object.id, object)
end

Public Instance Methods

==(other) click to toggle source

@param other [EmpireAvenue::Identity] @return [Boolean]

Calls superclass method
# File lib/empireavenue/identity.rb, line 41
def ==(other)
  super || attr_equal(:id, other) || attrs_equal(other)
end
id() click to toggle source

@return [Integer]

# File lib/empireavenue/identity.rb, line 46
def id
  @attrs[:id]
end