Module: Tramway::Forms::Normalizations

Included in:
BaseForm
Defined in:
lib/tramway/forms/normalizations.rb

Overview

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



36
37
38
# File 'lib/tramway/forms/normalizations.rb', line 36

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#__apply_normalizations(params) ⇒ Object

:reek:NilCheck { enabled: false }



41
42
43
44
45
46
47
48
49
50
# File 'lib/tramway/forms/normalizations.rb', line 41

def __apply_normalizations(params)
  self.class.normalizations.reduce(params) do |hash, (attribute, normalization)|
    value = hash[attribute]
    if hash.key?(attribute) && (!value.nil? || normalization[:apply_to_nil])
      hash.merge(attribute => instance_exec(value, &normalization[:proc]))
    else
      hash
    end
  end
end