module ActiveRecord::DefaultValues

Constants

VERSION

Public Instance Methods

default_value(attr_name, default_value, **options) click to toggle source
# File lib/active_record/default_values.rb, line 9
def default_value(attr_name, default_value, **options)
  after_initialize if: :new_record? do
    value = default_value.respond_to?(:call) ? default_value.call : default_value
    send("#{attr_name}=", value) if send(attr_name).send(options[:if] || :nil?)
  end
end