module Sequel::Plugins::Uuid::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/uuid.rb 45 def before_validation 46 set_uuid if new? 47 super 48 end
Set the uuid when creating
Calls superclass method
Private Instance Methods
Source
# File lib/sequel/plugins/uuid.rb 54 def create_uuid 55 SecureRandom.uuid 56 end
Create a new UUID. This method can be overridden to use a separate method for creating UUIDs.
Source
# 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
If the object has accessor methods for the uuid field, and the uuid value is nil or overwriting it is allowed, set the uuid.