Module: ParamsSanitizer::Sanitizers::AcceptRange::SanitizerMethods

Defined in:
lib/params_sanitizer/sanitizers/accept_range.rb

Instance Method Summary collapse

Instance Method Details

#accept_range(key, default_value, min = nil, max = nil) ⇒ Object

Define rule of accept range.

Examples:

accept_range :month, 1, 1, 12

Parameters:

  • key (String)

    key of parameter.

  • default_value (Object)

    default values when input not addmitted value.

  • min (Integer) (defaults to: nil)

    range of min.(when do not set a limit, nil)

  • max (Integer) (defaults to: nil)

    range of max.(when do not set a limit, nil)



49
50
51
52
53
# File 'lib/params_sanitizer/sanitizers/accept_range.rb', line 49

def accept_range(key, default_value, min = nil, max = nil)
  check_duplicated_definition!(key)
  definitions[:accept_range] ||= Hash.new
  definitions[:accept_range][key.to_s] = { default_value: default_value, min: min, max: max }
end