Class: Errapi::Validations::Inclusion
- Includes:
- Clusivity
- Defined in:
- lib/errapi/validations/inclusion.rb
Defined Under Namespace
Classes: Factory
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Inclusion
constructor
A new instance of Inclusion.
- #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 = {}) ⇒ Inclusion
Returns a new instance of Inclusion.
11 12 13 14 15 16 17 18 |
# File 'lib/errapi/validations/inclusion.rb', line 11 def initialize = {} unless key = exactly_one_option?(OPTIONS, ) raise ArgumentError, "Either :in or :within must be supplied (but not both)." end @delimiter = [key] check_delimiter! OPTIONS_DESCRIPTION end |
Instance Method Details
#validate(value, context, options = {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/errapi/validations/inclusion.rb', line 20 def validate value, context, = {} allowed_values = members OPTIONS_DESCRIPTION, unless include? allowed_values, value context.add_error reason: :not_included, check_value: allowed_values end end |