Module: HashMan::Inclusion::ClassMethods

Defined in:
lib/hashman/inclusion.rb

Instance Method Summary collapse

Instance Method Details

#generate_hash_id(id) ⇒ Object



26
27
28
# File 'lib/hashman/inclusion.rb', line 26

def generate_hash_id(id)
  hasher.encode(rinse_id(id))
end

#hash_length(number) ⇒ Object

generate the hash_id using the @magic_number declared in class id class === String || UUIDTools::UUID || Fixnum



22
23
24
# File 'lib/hashman/inclusion.rb', line 22

def hash_length(number)
  @magic_number = number
end

#reverse_hash(hash) ⇒ Object

reverse the has to get the original id if UUID, parse it and return the UUID object



33
34
35
36
# File 'lib/hashman/inclusion.rb', line 33

def reverse_hash(hash)
  id = hasher.decode(hash).try(:first)
  (self.include? Dynamoid::Document) || (self.columns_hash["id"].type == :uuid) ? UUIDTools::UUID.parse_int(id) : id
end