module Riveter::AttributeDefaultValues
Public Class Methods
attribute_defaults()
click to toggle source
# File lib/riveter/attribute_default_values.rb, line 12 def attribute_defaults @attribute_defaults ||= {} end
Public Instance Methods
set_defaults()
click to toggle source
# File lib/riveter/attribute_default_values.rb, line 57 def set_defaults return if self.respond_to?(:persisted?) && self.persisted? self.class.attribute_defaults.each do |attribute, value_or_proc| value = value_or_proc.respond_to?(:call) ? (value_or_proc.call(self) rescue value_or_proc.call) : value_or_proc send("#{attribute}=", value) if send(attribute).blank? end end