Class: DSLCompose::DSL::Arguments::Argument::FormatValidation
- Inherits:
-
Object
- Object
- DSLCompose::DSL::Arguments::Argument::FormatValidation
- Defined in:
- lib/dsl_compose/dsl/arguments/argument/format_validation.rb
Defined Under Namespace
Classes: ValidationFailedError
Instance Method Summary collapse
-
#initialize(regex) ⇒ FormatValidation
constructor
A new instance of FormatValidation.
- #validate!(value) ⇒ Object
Constructor Details
#initialize(regex) ⇒ FormatValidation
Returns a new instance of FormatValidation.
11 12 13 14 15 16 17 |
# File 'lib/dsl_compose/dsl/arguments/argument/format_validation.rb', line 11 def initialize regex unless regex.is_a?(Regexp) raise InvalidValueError, "The value `#{regex}` provided to this validator must be of type Regexp" end @regex = regex end |
Instance Method Details
#validate!(value) ⇒ Object
19 20 21 22 |
# File 'lib/dsl_compose/dsl/arguments/argument/format_validation.rb', line 19 def validate! value raise ValidationFailedError, "The argument is invalid. Expected format #{@regex} but received #{value}" if @regex.match(value).nil? true end |