Module: ActiveRecord::HashidsUri::ClassMethods
- Defined in:
- lib/hashids_uri.rb
Instance Method Summary collapse
Instance Method Details
#find(*args) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/hashids_uri.rb', line 28 def find(*args) id = args.first return super if args.count != 1 || (Integer(id) rescue false) find_by_hash(id).tap { |result| return result unless result.nil? } raise ActiveRecord::RecordNotFound, "cannot find record with hash id: #{id.inspect}" end |
#find_by_hash(hash) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/hashids_uri.rb', line 19 def find_by_hash(hash) decoded_id = ::Hashids.new( self.salt, self.min_length ).decode(hash).first find(decoded_id) end |
#has_hashids_uri(options = {}) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/hashids_uri.rb', line 12 def has_hashids_uri( = {}) class_attribute :salt, :min_length self.salt = .fetch(:salt, '') self.min_length = .fetch(:min_length, 6) end |