Module: ObfuscateId::ClassMethods

Defined in:
lib/obfuscate_id.rb

Instance Method Summary collapse

Instance Method Details

#deobfuscate_id(obfuscated_id) ⇒ Object



38
39
40
# File 'lib/obfuscate_id.rb', line 38

def deobfuscate_id(obfuscated_id)
  ObfuscateId.show(obfuscated_id, self.obfuscate_id_spin)
end

#find(*args) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/obfuscate_id.rb', line 21

def find(*args)
  scope = args.slice!(0)
  options = args.slice!(0) || {}
  if has_obfuscated_id? && !options[:no_obfuscated_id]
    if scope.is_a?(Array)
      scope.map! {|a| deobfuscate_id(a).to_i}
    else
      scope = deobfuscate_id(scope)
    end
  end
  super(scope)
end

#has_obfuscated_id?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/obfuscate_id.rb', line 34

def has_obfuscated_id?
  true
end

#obfuscate_id_default_spinObject

Generate a default spin from the Model name This makes it easy to drop obfuscate_id onto any model and produce different obfuscated ids for different models



45
46
47
48
49
50
51
# File 'lib/obfuscate_id.rb', line 45

def obfuscate_id_default_spin
  alphabet = Array("a".."z") 
  number = name.split("").collect do |char|
    alphabet.index(char)
  end
  number.shift(12).join.to_i
end