module UuidProperties::ClassMethods
Public Instance Methods
find_by_uuid(uuid, options={})
click to toggle source
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.
# File lib/uuid_properties.rb, line 26 def find_by_uuid(uuid, options={}) if uuid =~ UuidProperties::UUID_PATTERN # copy merge in case of incoming frozen hash options = options.merge(:conditions => ["#{table_name}.uuid = ?", uuid]) record = self.find(:first, options) record else nil end end
find_by_uuid!(uuid, options={})
click to toggle source
# File lib/uuid_properties.rb, line 37 def find_by_uuid!(uuid, options={}) unless uuid =~ UuidProperties::UUID_PATTERN raise ArgumentError, "Improperly formatted UUID." end # copy merge in case of incoming frozen hash options = options.merge(:conditions => ["#{table_name}.uuid = ?", uuid]) record = self.find(:first, options) record || raise(ActiveRecord::RecordNotFound) end