Module: ActiveRecord::Acts::HasUuid::InstanceMethods
- Defined in:
- lib/has_uuid.rb
Instance Method Summary collapse
Instance Method Details
#assign_uuid(options = {}) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/has_uuid.rb', line 40 def assign_uuid( = {}) return if uuid_valid? unless [:force] uuid = UUIDTools::UUID.send("#{uuid_generator}_create").to_s send("#{uuid_column}=", uuid) end |
#assign_uuid! ⇒ Object
47 48 49 50 |
# File 'lib/has_uuid.rb', line 47 def assign_uuid! assign_uuid(:force => true) save! end |
#uuid_valid? ⇒ Boolean
52 53 54 55 56 57 58 59 60 |
# File 'lib/has_uuid.rb', line 52 def uuid_valid? uuid = send(uuid_column) return false if uuid.blank? begin UUIDTools::UUID.parse(uuid).kind_of?(UUIDTools::UUID) rescue ArgumentError, TypeError false end end |