Class: Errapi::Validations::Exclusion
- Includes:
- Clusivity
- Defined in:
- lib/errapi/validations/exclusion.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Exclusion
constructor
A new instance of Exclusion.
- #validate(value, context, options = {}) ⇒ Object
Methods inherited from Base
#actual_option_value, #callable_option_type_error, #callable_option_value?, #callable_option_value_error, #exactly_one_option?
Constructor Details
#initialize(options = {}) ⇒ Exclusion
Returns a new instance of Exclusion.
7 8 9 10 11 12 13 14 |
# File 'lib/errapi/validations/exclusion.rb', line 7 def initialize = {} unless key = exactly_one_option?(OPTIONS, ) raise ArgumentError, "Either :from or :in or :within must be supplied (but only one of them)." end @delimiter = [key] check_delimiter! OPTIONS_DESCRIPTION end |
Instance Method Details
#validate(value, context, options = {}) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/errapi/validations/exclusion.rb', line 16 def validate value, context, = {} excluded_values = members OPTIONS_DESCRIPTION, if include? excluded_values, value context.add_error reason: :excluded, check_value: excluded_values end end |