Class: AuditLoggable::ChangeSet::EnumAttributesNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/audit_loggable/change_set.rb

Instance Method Summary collapse

Constructor Details

#initialize(klass, changes) ⇒ EnumAttributesNormalizer

Returns a new instance of EnumAttributesNormalizer.



27
28
29
30
# File 'lib/audit_loggable/change_set.rb', line 27

def initialize(klass, changes)
  @klass = klass
  @changes = changes
end

Instance Method Details

#callObject



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

def call
  @klass.defined_enums.each_pair.with_object(@changes.dup) do |(name, values), changes|
    next unless changes.key?(name)

    changes[name] =
      if changes[name].is_a? ::Array
        changes[name].map { |v| values[v] }
      else
        changes[name] = values[changes[name]]
      end
  end
end