class Aws::Templates::Utils::Parametrized::Getter::Path

Lookup value in options by path

Looks up value from options attribute by specified path. The path can be either statically specified or a block can be provided. The block shouldn't have parameters and should return an array containing path. The block will be executed in the instance context.

Example

class Piece
  include Aws::Templates::Utils::Parametrized

  parameter :param1, :getter => path(:a, :b)
end

i = Piece.new(:a => { :b => 3 })
i.param1 # => 3

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/aws/templates/utils/parametrized/getter/path.rb, line 29
def initialize(path)
  unless path.respond_to?(:to_proc) || path.respond_to?(:to_a)
    raise ArgumentError.new(
      "Path can be either array or Proc: #{path.inspect}"
    )
  end

  @path = path
end

Protected Instance Methods

get(_, instance) click to toggle source
# File lib/aws/templates/utils/parametrized/getter/path.rb, line 41
def get(_, instance)
  if path.respond_to?(:to_proc)
    instance.options[*instance.instance_eval(&path)]
  elsif path.respond_to?(:to_a)
    instance.options[*path]
  end
end