Module: Tramway::Forms::Normalizations::ClassMethods

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

Overview

A collection of methods that would be using in users forms

Instance Method Summary collapse

Instance Method Details

#__ancestor_normalizations(klass = superclass) ⇒ Object

:reek:ManualDispatch { enabled: false }



22
23
24
25
26
27
28
# File 'lib/tramway/forms/normalizations.rb', line 22

def __ancestor_normalizations(klass = superclass)
  superklass = klass.superclass

  return {} unless superklass.respond_to?(:normalizations)

  klass.normalizations.merge!(__ancestor_normalizations(superklass))
end

#__initialize_normalizations(subclass) ⇒ Object

:reek:UtilityFunction { enabled: false }



31
32
33
# File 'lib/tramway/forms/normalizations.rb', line 31

def __initialize_normalizations(subclass)
  subclass.instance_variable_set(:@normalizations, {})
end

#normalizationsObject



17
18
19
# File 'lib/tramway/forms/normalizations.rb', line 17

def normalizations
  __ancestor_normalizations.merge(@normalizations)
end

#normalizes(*attributes, with:, apply_to_nil: false) ⇒ Object

:reek:BooleanParameter { enabled: false }



11
12
13
14
15
# File 'lib/tramway/forms/normalizations.rb', line 11

def normalizes(*attributes, with:, apply_to_nil: false)
  attributes.each do |attribute|
    @normalizations.merge!(attribute => { proc: with, apply_to_nil: })
  end
end