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

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/utils/parametrized/transformations.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

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



531
532
533
534
535
536
537
# File 'lib/aws/templates/utils/parametrized/transformations.rb', line 531

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



549
550
551
552
553
# File 'lib/aws/templates/utils/parametrized/transformations.rb', line 549

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