Module: HashIds::Obfuscate::ClassMethods
- Defined in:
- lib/hash_ids/obfuscate.rb
Instance Method Summary collapse
- #find(*args) ⇒ Object
- #hash_ids?(ids) ⇒ Boolean
-
#hash_ids_decode(ids) ⇒ Object
return an string array.
- #hash_ids_encode(ids) ⇒ Object
-
#super_able?(args) ⇒ Boolean
check args super able.
Instance Method Details
#find(*args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hash_ids/obfuscate.rb', line 21 def find(*args) # invoke super condition return super if block_given? || super_able?(args) # decode hash id to true id if args.kind_of?(Array) args = args.first.kind_of?(Array) ? args.first : args args.map! do |id| hash_ids?(id) ? hash_ids_decode(id).first : id end args = args.length==1 ? args.first : args end super(args) end |
#hash_ids?(ids) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/hash_ids/obfuscate.rb', line 46 def hash_ids? ids ids = ids || '' ds = HashIds::hasher.decode ids.to_s return true unless ds.empty? end |
#hash_ids_decode(ids) ⇒ Object
return an string array
42 43 44 |
# File 'lib/hash_ids/obfuscate.rb', line 42 def hash_ids_decode ids HashIds::hasher.decode ids end |
#hash_ids_encode(ids) ⇒ Object
37 38 39 |
# File 'lib/hash_ids/obfuscate.rb', line 37 def hash_ids_encode ids HashIds::hasher.encode ids end |
#super_able?(args) ⇒ Boolean
check args super able
13 14 15 16 17 18 19 |
# File 'lib/hash_ids/obfuscate.rb', line 13 def super_able? args primary_key.nil? || default_scopes.any? || args.first.kind_of?(Hash) || args.first.kind_of?(Symbol) || columns_hash.include?(inheritance_column) end |