Class: Aws::Templates::Utils::Parametrized::Constraint::Requires
- Inherits:
-
Aws::Templates::Utils::Parametrized::Constraint
- Object
- Aws::Templates::Utils::Parametrized::Constraint
- Aws::Templates::Utils::Parametrized::Constraint::Requires
- Defined in:
- lib/aws/templates/utils/parametrized/constraints.rb
Overview
Check presence of parameters if the condition is met
Requires presence of the methods passed as dependencies in the current scope with non-nil returning values. Default condition for the value is not to be nil. The condition can be either a block or a value.
Example
class Piece
include Aws::Templates::Utils::Parametrized
parameter :param2
parameter :param1, :constraint => requires(:param2)
end
i = Piece.new(:param2 => 1)
i.param1 # => nil
i = Piece.new(:param1 => 1)
i.param1 # raise ParameterValueInvalid
i = Piece.new(:param1 => 2, :param2 => 1)
i.param1 # => 2
Instance Attribute Summary collapse
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#dependencies ⇒ Object
readonly
Returns the value of attribute dependencies.
Instance Method Summary collapse
- #if(*params, &blk) ⇒ Object
-
#initialize(dependencies) ⇒ Requires
constructor
A new instance of Requires.
Methods inherited from Aws::Templates::Utils::Parametrized::Constraint
Constructor Details
#initialize(dependencies) ⇒ Requires
Returns a new instance of Requires.
157 158 159 160 |
# File 'lib/aws/templates/utils/parametrized/constraints.rb', line 157 def initialize(dependencies) @dependencies = dependencies @condition = method(:not_nil?) end |
Instance Attribute Details
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
155 156 157 |
# File 'lib/aws/templates/utils/parametrized/constraints.rb', line 155 def condition @condition end |
#dependencies ⇒ Object (readonly)
Returns the value of attribute dependencies.
154 155 156 |
# File 'lib/aws/templates/utils/parametrized/constraints.rb', line 154 def dependencies @dependencies end |
Instance Method Details
#if(*params, &blk) ⇒ Object
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/aws/templates/utils/parametrized/constraints.rb', line 162 def if(*params, &blk) if params.empty? @condition = blk else test = params.first @condition = ->(v) { v == test } end self end |