Module: ActiveModelAttributes::ClassMethods

Defined in:
lib/active_model_attributes.rb

Instance Method Summary collapse

Instance Method Details

#attribute(name, type = ActiveModelAttributes::Type.default_value, **options) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_model_attributes.rb', line 33

def attribute(name, type = ActiveModelAttributes::Type.default_value, **options)
  name = name.to_s

  if type.is_a?(Symbol)
    type = ActiveModelAttributes::Type.lookup(type)
  end

  self._active_model_attributes_attribute_types = _active_model_attributes_attribute_types.merge(name => type)

  define_default_attribute(name, options.fetch(:default, NO_DEFAULT_PROVIDED))
  define_attribute_methods(name)
end