Class: Aws::Templates::Utils::Parametrized::Transformation::AsList
- Inherits:
-
Aws::Templates::Utils::Parametrized::Transformation
- Object
- Aws::Templates::Utils::Parametrized::Transformation
- Aws::Templates::Utils::Parametrized::Transformation::AsList
- Defined in:
- lib/aws/templates/utils/parametrized/transformation/as_list.rb
Overview
Transform input value into a list
Input value can be either an array or something which implements to_a method standard semantics. Each list entry is evaluated with specified constraints and transformations.
With as_list transformation you can have as many nested levels as it’s needed in terms of nested lists or nested objects.
Example
class Piece
include Aws::Templates::Utils::Parametrized
parameter :param1, :transform => as_list(
# alias for all elements. Plays a role during introspection
:name => :element,
# description of what the element represents
:description => 'List element',
# constraint for list element
:constraint => not_nil
)
parameter :param2, :transform => as_list(
:name => :element,
:description => 'List element',
:transform => as_list( # nested list
:name => :sub_element,
:description => 'Sub-list element',
:constraint => not_nil
)
)
parameter :param3, :transform => as_list(
:name => :particle,
:description => 'Small particle',
:transform => as_object( # nested object
Aws::Templates::Utils::AsNamed
)
)
end
i = Piece.new(:param1 => [1,2,3])
i.param1 # => [1,2,3]
i = Piece.new(:param1 => [1,nil,3])
i.param1 # throws exception
i = Piece.new(:param2 => [[1],[2],[3]])
i.param2 # => [[1],[2],[3]]
i = Piece.new(:param2 => [1,[2],[3]])
i.param2 # throws exception
i = Piece.new(:param2 => [[1],[nil],[3]])
i.param2 # throws exception
i = Piece.new(:param3 => [{:name => 'Zed'}])
i.param3.first.name # => 'Zed'
Instance Attribute Summary collapse
-
#sub_parameter ⇒ Object
readonly
Returns the value of attribute sub_parameter.
Instance Method Summary collapse
-
#initialize(klass = nil, options = nil) ⇒ AsList
constructor
A new instance of AsList.
Methods inherited from Aws::Templates::Utils::Parametrized::Transformation
Constructor Details
#initialize(klass = nil, options = nil) ⇒ AsList
Returns a new instance of AsList.
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/aws/templates/utils/parametrized/transformation/as_list.rb', line 64 def initialize(klass = nil, = nil) return if .nil? @sub_parameter = Parametrized::Parameter.new( [:name], klass, description: [:description], transform: [:transform], constraint: [:constraint] ) end |
Instance Attribute Details
#sub_parameter ⇒ Object (readonly)
Returns the value of attribute sub_parameter.
62 63 64 |
# File 'lib/aws/templates/utils/parametrized/transformation/as_list.rb', line 62 def sub_parameter @sub_parameter end |