Module: ParamsValidator::Filter

Extended by:
ActiveSupport::Inflector
Defined in:
lib/params_validator/filter.rb

Class Method Summary collapse

Class Method Details

.sanitize_params(params, definition) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/params_validator/filter.rb', line 5

def self.sanitize_params(params, definition)
  errors = {}
  definition.each do |field, validation_definition|
    errors = validate_field(field, params, validation_definition, errors)

    validation_definition.reject {|k,v| reserved_keys.include?(k) }.each do |nested_field, nested_validation_definition|
      sanitize_params(params[field.to_s], { nested_field => nested_validation_definition })
    end
  end
  raise InvalidParamsException.new(errors) unless errors.empty?
  params
end