Class: DSLCompose::DSL::Arguments::Argument::NotEndWithValidation
- Inherits:
-
Object
- Object
- DSLCompose::DSL::Arguments::Argument::NotEndWithValidation
show all
- Defined in:
- lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb
Defined Under Namespace
Classes: InvalidValueError, ValidationFailedError
Instance Method Summary
collapse
Constructor Details
14
15
16
17
|
# File 'lib/dsl_compose/dsl/arguments/argument/not_end_with_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
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb', line 19
def add_values values
if values.is_a?(Symbol) || values.is_a?(String)
values = [values]
end
unless values.is_a? Array
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
end
unless values.all? { |value| value.is_a? Symbol } || values.all? { |value| value.is_a? String }
raise ValidationFailedError, "The value `#{values}` provided to this validator must be a Symbol/String or an Array of Symbols/Strings"
end
@values += values
end
|
#validate!(value) ⇒ Object
38
39
40
41
|
# File 'lib/dsl_compose/dsl/arguments/argument/not_end_with_validation.rb', line 38
def validate! value
raise ValidationFailedError, "The argument is invalid. Expected `#{value}` to not end with `#{@values}`" if @values.filter { |v| value.end_with? v.to_s }.any?
true
end
|