Module: Sequel::Plugins::Uuid
- Defined in:
- lib/sequel/plugins/uuid.rb
Overview
The uuid plugin creates hooks that automatically create a uuid for every instance. Note that this uses SecureRandom.uuid to create UUIDs, and that method is not defined on ruby 1.8.7. If you would like to use this on ruby 1.8.7, you need to override the Model#create_uuid private method to return a valid uuid.
Usage:
# Uuid all model instances using +uuid+
# (called before loading subclasses)
Sequel::Model.plugin :uuid
# Uuid Album instances, with custom column name
Album.plugin :uuid, :field=>my_uuid
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Class Method Summary collapse
-
.configure(model, opts = OPTS) ⇒ Object
Configure the plugin by setting the available options.
Class Method Details
.configure(model, opts = OPTS) ⇒ Object
Configure the plugin by setting the available options. Note that if this method is run more than once, previous settings are ignored, and it will just use the settings given or the default settings. Options:
- :field
-
The field to hold the uuid (default: :uuid)
- :force
-
Whether to overwrite an existing uuid (default: false)
27 28 29 30 31 32 |
# File 'lib/sequel/plugins/uuid.rb', line 27 def self.configure(model, opts=OPTS) model.instance_eval do @uuid_field = opts[:field]||:uuid @uuid_overwrite = opts[:force]||false end end |