Class: Aws::Templates::Utils::Parametrized::Transformation

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/utils/parametrized/transformation.rb,
lib/aws/templates/utils/parametrized/transformation/dsl.rb,
lib/aws/templates/utils/parametrized/transformation/as_hash.rb,
lib/aws/templates/utils/parametrized/transformation/as_list.rb,
lib/aws/templates/utils/parametrized/transformation/as_chain.rb,
lib/aws/templates/utils/parametrized/transformation/as_module.rb,
lib/aws/templates/utils/parametrized/transformation/as_object.rb,
lib/aws/templates/utils/parametrized/transformation/as_string.rb,
lib/aws/templates/utils/parametrized/transformation/as_boolean.rb,
lib/aws/templates/utils/parametrized/transformation/as_integer.rb,
lib/aws/templates/utils/parametrized/transformation/as_rendered.rb

Overview

Transformation functor class

A transformation is a Proc accepting input value and providing output value which is expected to be a transformation of the input. The proc is executed in instance context so instance methods can be used for calculation.

The class implements functor pattern through to_proc method and closure. Essentially, all transformations can be used everywhere where a block is expected.

It provides protected method transform which should be overriden in all concrete transformation classes.

Defined Under Namespace

Modules: Dsl Classes: AsBoolean, AsChain, AsHash, AsInteger, AsList, AsModule, AsObject, AsRendered, AsString

Instance Method Summary collapse

Instance Method Details

#to_procObject

Creates closure with transformation invocation

It’s an interface method required for Transformation to expose functor properties. It encloses invocation of Transformation transform_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 2 parameters:

  • parameter - the Parameter object which the transformation

    will be performed for
    
  • value - parameter value to be transformed

…where instance is assumed from self



36
37
38
39
40
41
42
# File 'lib/aws/templates/utils/parametrized/transformation.rb', line 36

def to_proc
  transform = self

  lambda do |parameter, value|
    transform.transform_wrapper(parameter, value, self)
  end
end

#transform_wrapper(parameter, value, instance) ⇒ Object

Wraps transformation-dependent method

It wraps constraint-dependent “transform” method into a rescue block to standardize exception type and information provided by failed transformation calculation

  • parameter - the Parameter object which the transformation will

    be performed for
    
  • value - parameter value to be transformed

  • instance - the instance value is transform



54
55
56
57
58
# File 'lib/aws/templates/utils/parametrized/transformation.rb', line 54

def transform_wrapper(parameter, value, instance)
  transform(parameter, value, instance)
rescue StandardError
  raise Templates::Exception::NestedParameterException.new(parameter)
end