module Obfuscatable::ClassMethods
Public Instance Methods
deobfuscatable(obfuscated_id)
click to toggle source
# File lib/obfuscatable.rb, line 38 def deobfuscatable(obfuscated_id) Obfuscatable.show(obfuscated_id, self.obfuscatable_spin) end
find_obfuscated(*args)
click to toggle source
# File lib/obfuscatable.rb, line 21 def find_obfuscated(*args) scope = args.slice!(0) options = args.slice!(0) || {} if has_obfuscated_id? if scope.is_a?(Array) scope.map! {|a| deobfuscatable(a).to_i} else scope = deobfuscatable(scope).to_i end end find(scope) end
has_obfuscated_id?()
click to toggle source
# File lib/obfuscatable.rb, line 34 def has_obfuscated_id? true end
obfuscatable_default_spin()
click to toggle source
Generate a default spin from the Model name This makes it easy to drop obfuscatable onto any model and produce different obfuscated ids for different models
# File lib/obfuscatable.rb, line 45 def obfuscatable_default_spin alphabet = Array("a".."z") number = name.split("").collect do |char| alphabet.index(char) end number.shift(12).join.to_i end