class Aws::Templates::Utils::Parametrized::Constraint::Matches
Check if value matches the regular expression
Checks if value matches the regular expression. If value doesn't match, an exception will be thrown with attached description of regular expression and value converted to string.
Example¶ ↑
class Piece include Aws::Templates::Utils::Parametrized parameter :param1, constraint: matches('A+') end i = Piece.new(:param1 => 'Ask') i.param1 # => 'Ask' i = Piece.new(:param1 => 'Bar') i.param1 # raise ParameterValueInvalid
Attributes
expression[R]
Public Class Methods
new(rex)
click to toggle source
# File lib/aws/templates/utils/parametrized/constraint/matches.rb, line 29 def initialize(rex) @expression = Regexp.new(rex) end
Protected Instance Methods
check(parameter, value, _)
click to toggle source
# File lib/aws/templates/utils/parametrized/constraint/matches.rb, line 35 def check(parameter, value, _) return if expression =~ value.to_s raise "#{value} doesn't match #{expression} for parameter #{parameter.name}" end