Module: Hashid::Rails::ClassMethods
- Defined in:
- lib/hashid/rails.rb
Instance Method Summary collapse
Instance Method Details
#decode_id(id) ⇒ Object
53 54 55 |
# File 'lib/hashid/rails.rb', line 53 def decode_id(id) hashids.decode(id.to_s).first end |
#encode_id(id) ⇒ Object
49 50 51 |
# File 'lib/hashid/rails.rb', line 49 def encode_id(id) hashids.encode(id) end |
#find(hashid) ⇒ Object
57 58 59 |
# File 'lib/hashid/rails.rb', line 57 def find(hashid) model_reload? ? super(hashid) : super( decode_id(hashid) || hashid ) end |
#hashids ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hashid/rails.rb', line 38 def hashids secret = Hashid::Rails.configuration.secret length = Hashid::Rails.configuration.length alphabet = Hashid::Rails.configuration.alphabet arguments = ["#{table_name}#{secret}", length] arguments << alphabet if alphabet.present? Hashids.new(*arguments) end |