Class: Aws::Templates::Utils::Parametrized::Getter
- Inherits:
-
Object
- Object
- Aws::Templates::Utils::Parametrized::Getter
- Defined in:
- lib/aws/templates/utils/parametrized/getter.rb,
lib/aws/templates/utils/parametrized/getter/dsl.rb,
lib/aws/templates/utils/parametrized/getter/path.rb,
lib/aws/templates/utils/parametrized/getter/as_is.rb,
lib/aws/templates/utils/parametrized/getter/value.rb,
lib/aws/templates/utils/parametrized/getter/one_of.rb,
lib/aws/templates/utils/parametrized/getter/as_instance_variable.rb
Overview
Getter functor class
A getter is a Proc without parameters and it is expected to return a value. Since the proc is to be executed in instance context the value can be calculated based on other methods or extracted from options attrribute
The class implements functor pattern through to_proc method and closure. Essentially, all getters can be used everywhere where a block is expected.
It provides protected method get which should be overriden in all concrete getter classes.
Direct Known Subclasses
Defined Under Namespace
Modules: Dsl Classes: AsInstanceVariable, AsIs, OneOf, Path, Value
Instance Method Summary collapse
-
#get_wrapper(parameter, instance) ⇒ Object
Wraps getter-dependent method.
-
#to_proc ⇒ Object
Creates closure with getter invocation.
Instance Method Details
#get_wrapper(parameter, instance) ⇒ Object
Wraps getter-dependent method
It wraps constraint-dependent “get” method into a rescue block to standardize exception type and information provided by failed value calculation
-
parameter
- the Parameter object which the getter is executed for -
instance
- the instance value is taken from
49 50 51 52 53 |
# File 'lib/aws/templates/utils/parametrized/getter.rb', line 49 def get_wrapper(parameter, instance) get(parameter, instance) rescue StandardError raise Templates::Exception::NestedParameterException.new(parameter) end |
#to_proc ⇒ Object
Creates closure with getter invocation
It’s an interface method required for Getter to expose functor properties. It encloses invocation of Getter get_wrapper method into a closure. The closure itself is executed in the context of Parametrized instance which provides proper set “self” variable.
The closure itself accepts 1 parameters
-
parameter
- the Parameter object which the getter is executed for
…where instance is assumed from self
33 34 35 36 37 38 39 |
# File 'lib/aws/templates/utils/parametrized/getter.rb', line 33 def to_proc getter = self lambda do |parameter| getter.get_wrapper(parameter, self) end end |