class Errapi::Validations::Exclusion

Constants

OPTIONS
OPTIONS_DESCRIPTION

Public Class Methods

new(options = {}) click to toggle source
# File lib/errapi/validations/exclusion.rb, line 11
def initialize options = {}
  unless key = exactly_one_option?(OPTIONS, options)
    raise ArgumentError, "Either :from or :in or :within must be supplied (but only one of them)."
  end

  @delimiter = options[key]
  check_delimiter! OPTIONS_DESCRIPTION
end

Public Instance Methods

validate(value, context, options = {}) click to toggle source
# File lib/errapi/validations/exclusion.rb, line 20
def validate value, context, options = {}
  excluded_values = members OPTIONS_DESCRIPTION, options
  if include? excluded_values, value
    context.add_error reason: :excluded, check_value: excluded_values
  end
end