class HashIdentable::Identity

Attributes

id[R]
klass[R]

Public Class Methods

find(encoded_id) click to toggle source
# File lib/hash_identable/identity.rb, line 43
def self.find(encoded_id)
  decoded = HshFunction.decode(encoded_id)
  klass = HashIdentable.lookup_table.fetch(decoded[0]){ raise NoObjectRegistered, "No object registered" }
  new klass, decoded[1]
end
new(klass, id) click to toggle source
# File lib/hash_identable/identity.rb, line 9
def initialize klass, id
  @klass = klass.to_s
  @id = id
end

Public Instance Methods

encoded_id() click to toggle source
# File lib/hash_identable/identity.rb, line 27
def encoded_id
  id_wrapper.encode(hash_key)
end
hash_key() click to toggle source
# File lib/hash_identable/identity.rb, line 22
def hash_key
  raise "An ID is required to build a #hash_key" if id.nil? or klass.nil?
  return [hash_table_id, id]
end
hash_table_id() click to toggle source
# File lib/hash_identable/identity.rb, line 18
def hash_table_id
  @hash_table_id ||= HashIdentable.lookup_table.fetch_id(klass){ raise NoObjectRegistered, "No object registered" }
end
klass_constant() click to toggle source
# File lib/hash_identable/identity.rb, line 39
def klass_constant
  klass.constantize
end
to_h() click to toggle source
# File lib/hash_identable/identity.rb, line 31
def to_h
  {
    klass: klass,
    id: id,
    encoded_id: encoded_id
  }
end
to_s() click to toggle source
# File lib/hash_identable/identity.rb, line 14
def to_s
  encoded_id.to_s
end

Private Instance Methods

id_wrapper() click to toggle source
# File lib/hash_identable/identity.rb, line 51
def id_wrapper
  HshFunction
end