module Sequel::Plugins::Uuid::InstanceMethods
Public Instance Methods
before_validation()
click to toggle source
Set the uuid when creating
Calls superclass method
# File lib/sequel/plugins/uuid.rb 45 def before_validation 46 set_uuid if new? 47 super 48 end
Private Instance Methods
create_uuid()
click to toggle source
Create a new UUID. This method can be overridden to use a separate method for creating UUIDs.
# File lib/sequel/plugins/uuid.rb 54 def create_uuid 55 SecureRandom.uuid 56 end
set_uuid(uuid=create_uuid)
click to toggle source
If the object has accessor methods for the uuid field, and the uuid value is nil or overwriting it is allowed, set the uuid.
# File lib/sequel/plugins/uuid.rb 60 def set_uuid(uuid=create_uuid) 61 field = model.uuid_field 62 meth = :"#{field}=" 63 if respond_to?(field) && respond_to?(meth) && (model.uuid_overwrite? || get_column_value(field).nil?) 64 set_column_value(meth, uuid) 65 end 66 end