Module: ParamsChecker::Helper

Extended by:
Helper
Included in:
Helper
Defined in:
lib/params_checker/helper.rb

Instance Method Summary collapse

Instance Method Details

#check_type(type: '', values: []) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/params_checker/helper.rb', line 7

def check_type(
  type: '',
  values: []
)
  case type
  when 'integer'
    raise "This field's type must be integer." if values.any? { |value| !value.is_a?(Integer) }
  when 'numeric'
    raise "This field's type must be numeric." if values.any? { |value| !value.is_a?(Numeric) }
  when 'boolean'
    raise "This field's type must be boolean." if values.any? { |value| !value.in? [true, false] }
  end
end