Module: ObfuscateId::ClassMethods
- Defined in:
- lib/obfuscate_id.rb
Instance Method Summary collapse
- #deobfuscate_id(obfuscated_id) ⇒ Object
- #find(*args) ⇒ Object
- #has_obfuscated_id? ⇒ Boolean
-
#obfuscate_id_default_spin ⇒ Object
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.
Instance Method Details
#deobfuscate_id(obfuscated_id) ⇒ Object
38 39 40 |
# File 'lib/obfuscate_id.rb', line 38 def deobfuscate_id() ObfuscateId.show(, 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) = args.slice!(0) || {} if && ![: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
34 35 36 |
# File 'lib/obfuscate_id.rb', line 34 def true end |
#obfuscate_id_default_spin ⇒ Object
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 |