Class: DSLCompose::DSL::Arguments::Argument::InValidation

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

Defined Under Namespace

Classes: InvalidValueError, ValidationFailedError

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ InValidation

Returns a new instance of InValidation.



14
15
16
17
# File 'lib/dsl_compose/dsl/arguments/argument/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/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/in_validation.rb', line 27

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