class Aws::Templates::Utils::Parametrized::Constraint::SatisfiesCondition

Check if value satisfies the condition

Checks if value satisfies the condition defined in the block which should return true if the condition is met and false if it's not. If value fails the check, an exception will be thrown with attached condition description. The description is a part of constraint definition.

The block is evaluated in the functor's invocation context.

Example

class Piece
  include Aws::Templates::Utils::Parametrized
  parameter :param1,
    :constraint => satisfies('Mediocre value') { |v| v < 100 }
end

i = Piece.new(:param2 => 1)
i.param1 # => 1
i = Piece.new(:param1 => 101)
i.param1 # raise ParameterValueInvalid

Attributes

condition[R]
description[R]

Public Class Methods

new(description, &cond_block) click to toggle source
# File lib/aws/templates/utils/parametrized/constraint/satisfies_condition.rb, line 35
def initialize(description, &cond_block)
  @condition = cond_block
  @description = description
end

Protected Instance Methods

check(parameter, value, instance) click to toggle source
# File lib/aws/templates/utils/parametrized/constraint/satisfies_condition.rb, line 42
def check(parameter, value, instance)
  return if instance.instance_exec(value, &condition)

  raise(
    "#{value.inspect} doesn't satisfy the condition " \
    "#{description} for parameter #{parameter.name}"
  )
end