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

Filter functor class

A filter is a Proc accepting input hash and providing output hash which is expected to be a permutation of the input. The proc is executed in instance context so instance methods can be used for calculation.

The class implements functor pattern through to_proc method and closure. Essentially, all filters can be used everywhere where a block is expected.

It provides protected method filter which should be overriden in all concrete filter classes.

Public Instance Methods

&(other) click to toggle source

Chain filters

# File lib/aws/templates/utils/contextualized/filter.rb, line 25
def &(other)
  fltr = other.to_filter
  return self if fltr.is_a?(Identity)
  Chain.new(self, fltr)
end
filter(opts, memo, instance) click to toggle source

Filter method

  • opts - input hash to be filtered

  • instance - the instance filter is executed in

# File lib/aws/templates/utils/contextualized/filter.rb, line 53
def filter(opts, memo, instance); end
to_filter() click to toggle source
# File lib/aws/templates/utils/contextualized/filter.rb, line 55
def to_filter
  self
end
to_proc() click to toggle source

Creates closure with filter invocation

It's an interface method required for Filter to expose functor properties. It encloses invocation of Filter filter method into a closure. The closure itself is executed in the context of Filtered instance which provides proper set “self” variable.

The closure itself accepts just one parameter:

  • opts - input hash to be filtered

…where instance is assumed from self

# File lib/aws/templates/utils/contextualized/filter.rb, line 43
def to_proc
  fltr = self
  ->(opts, memo = {}) { fltr.filter(opts, memo, self) }
end