module HashMan::Inclusion::ClassMethods

Public Instance Methods

generate_hash_id(id) click to toggle source
# File lib/hashman/inclusion.rb, line 26
def generate_hash_id(id)
  hasher.encode(rinse_id(id))
end
hash_length(number) click to toggle source

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

# File lib/hashman/inclusion.rb, line 22
def hash_length(number)
  @magic_number = number
end
reverse_hash(hash) click to toggle source

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

# 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

Private Instance Methods

hasher() click to toggle source
# File lib/hashman/inclusion.rb, line 40
def hasher
  Hashman::Hasher.new("#{Rails.application.secrets.magic_number}", @magic_number || 4)
end
rinse_id(id) click to toggle source

standardize the id integer we do not specify UUIDTools since comparisons break! String (activeUUID tables), FixNum (normal ids), UUID (dynamoid/VideoClips)

# File lib/hashman/inclusion.rb, line 48
def rinse_id(id)
  case
    when id.class == String
      return UUIDTools::UUID.parse(id).to_i
    when id.class == Fixnum
      return id
    else
      return id.to_i
  end
end