Class: DSLCompose::DSL::Arguments::Argument::NotInValidation

Inherits:
Object
  • Object
show all
Defined in:
lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb

Defined Under Namespace

Classes: InvalidValueError, ValidationFailedError

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ NotInValidation

Returns a new instance of NotInValidation.



14
15
16
17
# File 'lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb', line 14

def initialize values
  @values = []
  add_values values
end

Instance Method Details

#add_values(values) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb', line 19

def add_values values
  unless values.is_a?(Array)
    raise InvalidValueError, "The value `#{values}` provided to this validator must be of type Array"
  end

  @values += values
end

#validate!(value) ⇒ Object



27
28
29
30
# File 'lib/dsl_compose/dsl/arguments/argument/not_in_validation.rb', line 27

def validate! value
  raise ValidationFailedError, "The argument is invalid. Expected not in #{@values} but received #{value}" if @values.include?(value)
  true
end