Module: Enumerize::ActiveRecordSupport::InstanceMethods

Defined in:
lib/enumerize/activerecord.rb

Instance Method Summary collapse

Instance Method Details

#becomes(klass) ⇒ Object

Support multiple enumerized attributes



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/enumerize/activerecord.rb', line 31

def becomes(klass)
  became = super
  klass.enumerized_attributes.each do |attr|
    # Rescue when column associated to the enum does not exist.
    begin
      became.send("#{attr.name}=", send(attr.name))
    rescue ActiveModel::MissingAttributeError
    end
  end

  became
end

#write_attribute(attr_name, value, *options) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/enumerize/activerecord.rb', line 22

def write_attribute(attr_name, value, *options)
  if self.class.enumerized_attributes[attr_name]
    _enumerized_values_for_validation[attr_name.to_s] = value
  end

  super
end