class Aws::Templates::Utils::Contextualized::Filter::Add

Add specified keys into the hash

Selective version of Copy filter. It adds key-value pairs or whole subtrees from options into the memo hash. It does this according to specified schema represented by combination of nested hashes and arrays. User can specify addition of values at arbitrary depth in options hash hierarchy with arbitrar granularity.

Example

class Piece
  include Aws::Templates::Utils::Contextualized

  contextualize filter(:add, :a, :b, c: [:d])
end

i = Piece.new()
opts = Options.new(a: { q: 1 }, b: 2, c: { d: { r: 5 }, e: 1 })
opts.filter(i.filter) # => { a: { q: 1 }, b: 2, c: { d: { r: 5 } } }

Public Instance Methods

filter(options, memo, _) click to toggle source
# File lib/aws/templates/utils/contextualized/filter/add.rb, line 30
def filter(options, memo, _)
  _recurse_add(options, memo, scheme)
end

Private Instance Methods

_list_add(opts, memo, list) click to toggle source
# File lib/aws/templates/utils/contextualized/filter/add.rb, line 48
def _list_add(opts, memo, list)
  list.each { |field| memo[field] = Utils.merge(memo[field], opts[field]) }
end
_recurse_add(opts, memo, schm) click to toggle source
# File lib/aws/templates/utils/contextualized/filter/add.rb, line 36
def _recurse_add(opts, memo, schm)
  return unless Utils.recursive?(opts)

  if Utils.hashable?(schm)
    _scheme_add(opts, memo, schm.to_hash)
  elsif Utils.list?(schm)
    _list_add(opts, memo, schm.to_ary)
  end

  memo
end
_scheme_add(opts, memo, schm) click to toggle source
# File lib/aws/templates/utils/contextualized/filter/add.rb, line 52
def _scheme_add(opts, memo, schm)
  schm.each_pair do |field, sub_scheme|
    next unless opts.include?(field)
    memo[field] = if sub_scheme.nil?
      Utils.merge(memo[field], opts[field])
    else
      _recurse_add(opts[field], memo[field] || {}, sub_scheme)
    end
  end
end