Module: Sequel::Plugins::DefaultsSetter

Defined in:
lib/sequel/plugins/defaults_setter.rb

Overview

The defaults_setter plugin makes the column getter methods return the default values for new objects, if the values have not already been set. Example:

# column a default NULL
# column b default 2
album = Album.new
album.a # => nil
album.b # => 2
album = Album.new(:a=>1, :b=>3)
album.a # => 1
album.b # => 3

Usage:

# Make all model subclass instances set defaults (called before loading subclasses)
Sequel::Model.plugin :defaults_setter

# Make the Album class set defaults 
Album.plugin :defaults_setter

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.configure(model) ⇒ Object

Set the default values based on the model schema



24
25
26
# File 'lib/sequel/plugins/defaults_setter.rb', line 24

def self.configure(model)
  model.send(:set_default_values)
end