Class: Aws::Templates::Utils::Parametrized::Transformation::AsObject
- Inherits:
-
Aws::Templates::Utils::Parametrized::Transformation
- Object
- Aws::Templates::Utils::Parametrized::Transformation
- Aws::Templates::Utils::Parametrized::Transformation::AsObject
- Defined in:
- lib/aws/templates/utils/parametrized/transformation/as_object.rb
Overview
Transform input value into the object
Input value can be either hash or object. The transformation performs nested object evaluation recusrsively as the input were Parametrized instance. As a parameter for the transformation you can specify either Module which mixes in Parametrized or to use a block which is to be evaluated as a part of Parametrized definition or both.
With as_object transformation you can have as many nested levels as it’s needed.
Example
class Piece
include Aws::Templates::Utils::Parametrized
parameter :param1,
:transform => as_object(Aws::Templates::Utils::AsNamed)
parameter :param2, :transform => as_object {
parameter :id, :description => 'Just ID',
:constraint => not_nil
}
parameter :param3,
:transform => as_object(Aws::Templates::Utils::AsNamed) {
parameter :path, :description => 'Just path',
:constraint => not_nil
}
end
i = Piece.new
i.param1 # => nil
i = Piece.new(:param1 => {:name => 'Zed'})
i.param1.name # => 'Zed'
i = Piece.new(:param2 => {:id => 123})
i.param2.id # => 123
i = Piece.new(:param3 => {:path => 'a/b', :name => 'Rex'})
i.param3.path # => 'a/b'
i.param3.name # => 123
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(scope, klass = nil, &definition) ⇒ AsObject
constructor
A new instance of AsObject.
Methods inherited from Aws::Templates::Utils::Parametrized::Transformation
Constructor Details
#initialize(scope, klass = nil, &definition) ⇒ AsObject
Returns a new instance of AsObject.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/aws/templates/utils/parametrized/transformation/as_object.rb', line 51 def initialize(scope, klass = nil, &definition) @klass = if klass.nil? Parametrized::Nested.create_class(scope) elsif klass.is_a?(Class) klass elsif klass.is_a?(Module) Parametrized::Nested.create_class(scope).with(klass) else raise "#{klass} is neither a class nor a module" end @klass.class_eval(&definition) unless definition.nil? end |
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
49 50 51 |
# File 'lib/aws/templates/utils/parametrized/transformation/as_object.rb', line 49 def klass @klass end |