Class: DSLCompose::DSL::Arguments::Argument::LengthValidation
- Inherits:
-
Object
- Object
- DSLCompose::DSL::Arguments::Argument::LengthValidation
- Defined in:
- lib/dsl_compose/dsl/arguments/argument/length_validation.rb
Defined Under Namespace
Classes: ValidationFailedError
Instance Method Summary collapse
-
#initialize(maximum: nil, minimum: nil, is: nil) ⇒ LengthValidation
constructor
A new instance of LengthValidation.
- #validate!(value) ⇒ Object
Constructor Details
#initialize(maximum: nil, minimum: nil, is: nil) ⇒ LengthValidation
Returns a new instance of LengthValidation.
11 12 13 14 15 |
# File 'lib/dsl_compose/dsl/arguments/argument/length_validation.rb', line 11 def initialize maximum: nil, minimum: nil, is: nil @maximum = maximum @minimum = minimum @is = is end |
Instance Method Details
#validate!(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dsl_compose/dsl/arguments/argument/length_validation.rb', line 17 def validate! value maximum = @maximum unless maximum.nil? raise ValidationFailedError, "The argument is invalid. Expected #{value} to be less than or equal to #{maximum} characters" if value.length > maximum end minimum = @minimum unless minimum.nil? raise ValidationFailedError, "The argument is invalid. Expected #{value} to be greater than or equal to #{minimum} characters" if value.length < minimum end is = @is unless is.nil? raise ValidationFailedError, "The argument is invalid. Expected #{value} to be #{is} characters long" if value.length != is end true end |