Module: Heatwave::AttributeNormalizing

Extended by:
ActiveSupport::Concern
Included in:
Customer::NewCustomer, Customer::PricingProgramAssigner, Pdf::Document::PriceList, Report::BaseCommand
Defined in:
app/concerns/heatwave/attribute_normalizing.rb

Overview

ActiveSupport::Concern mixin: attribute normalizing.

Class Method Summary collapse

Class Method Details

.normalize(*attrs, with: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/concerns/heatwave/attribute_normalizing.rb', line 31

def normalize(*attrs, with: nil)
  chain = Array(with).map(&:to_sym)
  attrs.each do |attr|
    define_method("#{attr}=") do |value|
      normalized = if chain.empty?
                     Heatwave::Normalizers.default(value)
                   else
                     Heatwave::Normalizers.chain(value, *chain)
                   end
      super(normalized)
    end
  end
end