Module: ActiveRecord::Uuid::FinderMethods
- Defined in:
- lib/active_record/uuid/finder_methods.rb
Constant Summary collapse
- VALID_UUID =
/[0-9A-F]{32}/i
Instance Method Summary collapse
- #exists?(id = false) ⇒ Boolean
-
#find_one(id) ⇒ Object
Ultimately, many methods call #find_one rather than simply just #find.
Instance Method Details
#exists?(id = false) ⇒ Boolean
16 17 18 19 20 21 22 |
# File 'lib/active_record/uuid/finder_methods.rb', line 16 def exists?(id = false) if id.to_s.gsub('-', '') =~ VALID_UUID super :uuid => id else super end end |
#find_one(id) ⇒ Object
Ultimately, many methods call #find_one rather than simply just #find. Overriding just this allows more things to just work properly.
8 9 10 11 12 13 14 |
# File 'lib/active_record/uuid/finder_methods.rb', line 8 def find_one(id) if id.to_s.gsub('-', '') =~ VALID_UUID && record = where(:uuid => id).limit(1).first record else super(id) end end |