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, line 45
def before_validation
  set_uuid if new?
  super
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, line 54
def create_uuid
  SecureRandom.uuid
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, line 60
def set_uuid(uuid=create_uuid)
  field = model.uuid_field
  meth = :"#{field}="
  if respond_to?(field) && respond_to?(meth) && (model.uuid_overwrite? || get_column_value(field).nil?)
    set_column_value(meth, uuid)
  end
end