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

Inherits:
Aws::Templates::Utils::Parametrized::Transformation show all
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

Instance Method Summary collapse

Methods inherited from Aws::Templates::Utils::Parametrized::Transformation

#to_proc, #transform_wrapper

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, options = nil)
  return if options.nil?

  @sub_parameter = Parametrized::Parameter.new(
    options[:name],
    klass,
    description: options[:description],
    transform: options[:transform],
    constraint: options[:constraint]
  )
end

Instance Attribute Details

#sub_parameterObject (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