Method: SimpleModel::Attributes::ClassMethods#default_attribute_settings

Defined in:
lib/simple_model/attributes.rb

#default_attribute_settingsObject

The default settings for a SimpeModel class Options:

  • :on_set - accepts a lambda that is run when an attribute is set

  • :on_get - accepts a lambda that is run when you get/read an attribute

  • :default - the default value for the attribute, can be a symbol that is sent for a method

  • :initialize - informations the object whether or not it should initialize the attribute with :default value, defaults to true

** If :initialize is set to false you must set :allow_blank to false or it will never set the default value

  • :allow_blank - when set to false, if an attributes value is blank attempts to set the default value, defaults to true



143
144
145
146
147
148
149
150
# File 'lib/simple_model/attributes.rb', line 143

def default_attribute_settings
  @default_attribute_settings ||= {:attributes_method => :attributes,
                                   :on_set => lambda {|obj,attr| attr},
                                   :on_get => lambda {|obj,attr| attr},
                                   :allow_blank => true,
                                   :initialize => true
                                   }
end