Module: RubyEnum::ActiveModel::AttrEnum

Extended by:
ActiveSupport::Concern
Defined in:
lib/ruby_enum/active_model.rb

Instance Method Summary collapse

Instance Method Details

#assign_attributes(new_attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ruby_enum/active_model.rb', line 8

def assign_attributes(new_attributes)
  if new_attributes
    enumeration_attrs = self.class.attr_enums

    new_attributes.each do |k, v|
      enum_attr = enumeration_attrs[k.to_sym]

      if enum_attr.present? && _is_not_enum?(v)
        enum_class_name = enum_attr[:class_name]
        enum_class = Object.const_get enum_class_name
        new_attributes[k] = enum_class.find_by_value(v)
      end
    end
  end

  super
end