module Sequel::Plugins::Uuid::InstanceMethods
Private Instance Methods
_before_validation()
click to toggle source
Set the uuid when creating
Calls superclass method
# File lib/sequel/plugins/uuid.rb, line 50 def _before_validation set_uuid if new? super end
create_uuid()
click to toggle source
Create a new UUID. This method can be overridden to use a separate method for creating UUIDs. Note that this method does not work on ruby 1.8.7, you will have to override it if you are using ruby 1.8.7.
# File lib/sequel/plugins/uuid.rb, line 58 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 64 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