Module: Sequel::Plugins::DefaultsSetter::InstanceMethods
- Defined in:
- lib/sequel/plugins/defaults_setter.rb
Instance Method Summary collapse
-
#[](k) ⇒ Object
Use default value for a new record if values doesn’t already contain an entry for it.
Instance Method Details
#[](k) ⇒ Object
Use default value for a new record if values doesn’t already contain an entry for it.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/sequel/plugins/defaults_setter.rb', line 139 def [](k) if new? && !values.has_key?(k) v = model.default_values.fetch(k){return} if v.respond_to?(:call) v = if v.respond_to?(:arity) && v.arity == 1 v.call(self) else v.call end end values[k] = v if model.cache_default_values? v else super end end |