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

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/templates/utils/contextualized/filters.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

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

Instance Method Summary collapse

Instance Method Details

#&(other) ⇒ Object

Chain filters



370
371
372
373
374
# File 'lib/aws/templates/utils/contextualized/filters.rb', line 370

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



398
# File 'lib/aws/templates/utils/contextualized/filters.rb', line 398

def filter(opts, memo, instance); end

#to_filterObject



400
401
402
# File 'lib/aws/templates/utils/contextualized/filters.rb', line 400

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



388
389
390
391
# File 'lib/aws/templates/utils/contextualized/filters.rb', line 388

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