Module: ParamsSanitizer::Sanitizers::AcceptRegex::SanitizerMethods

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

Instance Method Summary collapse

Instance Method Details

#accept_regex(key, default_value, regex) ⇒ Object

Define rule of accept regex.

Examples:

accept_regex(:age, 0, /^\d+$/)

Parameters:

  • key (String)

    key of parameter.

  • default_value (Object)

    default values when input not addmitted value.

  • regex (Regexp)

    accept when regex match.



45
46
47
48
49
# File 'lib/params_sanitizer/sanitizers/accept_regex.rb', line 45

def accept_regex(key, default_value, regex)
  check_duplicated_definition!(key)
  definitions[:accept_regex] ||= Hash.new
  definitions[:accept_regex][key.to_s] = { default_value: default_value, regex: regex }
end