Module: UuidProperties::ClassMethods
- Defined in:
- lib/uuid_properties.rb
Instance Method Summary collapse
-
#find_by_uuid(uuid, options = {}) ⇒ Object
Postgres will blow up when a UUID type is compared to a string, so sanitize our input first.
- #find_by_uuid!(uuid, options = {}) ⇒ Object
Instance Method Details
#find_by_uuid(uuid, options = {}) ⇒ Object
Postgres will blow up when a UUID type is compared to a string, so sanitize our input first. This also makes sense as a performance optimization – if the input isn’t a UUID anyway, it doesn’t make any sense to go to the database.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/uuid_properties.rb', line 26 def find_by_uuid(uuid, ={}) if uuid =~ UuidProperties::UUID_PATTERN # copy merge in case of incoming frozen hash = .merge(:conditions => ["#{table_name}.uuid = ?", uuid]) record = self.find(:first, ) record else nil end end |
#find_by_uuid!(uuid, options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/uuid_properties.rb', line 37 def find_by_uuid!(uuid, ={}) unless uuid =~ UuidProperties::UUID_PATTERN raise ArgumentError, "Improperly formatted UUID." end # copy merge in case of incoming frozen hash = .merge(:conditions => ["#{table_name}.uuid = ?", uuid]) record = self.find(:first, ) record || raise(ActiveRecord::RecordNotFound) end |