class Delta::Identifier

Attributes

keys[RW]

Public Class Methods

new(keys) click to toggle source
# File lib/delta/identifier.rb, line 3
def initialize(keys)
  self.keys = keys
end

Public Instance Methods

identities(collection) click to toggle source
# File lib/delta/identifier.rb, line 11
def identities(collection)
  cache(collection) { Hash[keys.map { |k| [k, collection.pluck(k).uniq] }] }
end
identity(object) click to toggle source
# File lib/delta/identifier.rb, line 7
def identity(object)
  cache(object) { Hash[keys.map { |k| [k, object.public_send(k)] }] }
end

Private Instance Methods

cache(key) { || ... } click to toggle source
# File lib/delta/identifier.rb, line 19
def cache(key)
  @cache ||= {}
  @cache.key?(key) ? @cache.fetch(key) : @cache[key] = yield
end