Class: Monban::ParamTransformer

Inherits:
Object
  • Object
show all
Defined in:
lib/monban/param_transformer.rb

Overview

Parameter transformer. Sanitizes and transforms parameter values

Since:

  • 1.0.0

Instance Method Summary collapse

Constructor Details

#initialize(params, transformations) ⇒ ParamTransformer

Initialize parameter transformer

Parameters:

  • params (ActionController::Parameters)

    parameters to be altered

Since:

  • 1.0.0



8
9
10
11
# File 'lib/monban/param_transformer.rb', line 8

def initialize(params, transformations)
  @params = params
  @transformations = transformations
end

Instance Method Details

#to_hObject

Returns the transformed parameters

Since:

  • 1.0.0



14
15
16
17
18
# File 'lib/monban/param_transformer.rb', line 14

def to_h
  sanitized_params.each_with_object({}) do |(key, value), hash|
    hash[key] = transform(key, value)
  end
end