Class: Aws::Templates::Utils::Contextualized::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/utils/contextualized/filter.rb,
lib/aws/templates/utils/contextualized/filter/add.rb,
lib/aws/templates/utils/contextualized/filter/dsl.rb,
lib/aws/templates/utils/contextualized/filter/copy.rb,
lib/aws/templates/utils/contextualized/filter/chain.rb,
lib/aws/templates/utils/contextualized/filter/proxy.rb,
lib/aws/templates/utils/contextualized/filter/remove.rb,
lib/aws/templates/utils/contextualized/filter/scoped.rb,
lib/aws/templates/utils/contextualized/filter/identity.rb,
lib/aws/templates/utils/contextualized/filter/override.rb,
lib/aws/templates/utils/contextualized/filter/recursive_schema_filter.rb

Overview

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.

Direct Known Subclasses

Chain, Copy, Identity, Override, Proxy, RecursiveSchemaFilter, Scoped

Defined Under Namespace

Modules: Dsl Classes: Add, Chain, Copy, Identity, Override, Proxy, RecursiveSchemaFilter, Remove, Scoped

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

Chain filters



25
26
27
28
29
# 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) ⇒ Object

Filter method

  • opts - input hash to be filtered

  • instance - the instance filter is executed in



53
# File 'lib/aws/templates/utils/contextualized/filter.rb', line 53

def filter(opts, memo, instance); end

#to_filterObject



55
56
57
# File 'lib/aws/templates/utils/contextualized/filter.rb', line 55

def to_filter
  self
end

#to_procObject

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



43
44
45
46
# File 'lib/aws/templates/utils/contextualized/filter.rb', line 43

def to_proc
  fltr = self
  ->(opts, memo = {}) { fltr.filter(opts, memo, self) }
end