module Aws::Templates::Utils::Contextualized
Contextualized
mixin.
It implements class instance-based definitions of context filters. Filters are options hash alterations and transformations which are defined per-class basis and combined according to class hierarchy when invoked. The target mixing entity should be either Module
or Class. In the former case it's possible to model set of object which have common traits organized as an arbitrary graph with many-to-many relationship.
Important difference from defaults is that the final result returned by “filter” mixed method is a functor. No operations are performed on options.
Public Instance Methods
# File lib/aws/templates/utils/contextualized.rb, line 54 def _set_context(new_context) @context = Filter::Scoped.new(new_context, self) self end
Context functor
It's a mixin method returning resulting context filter functor with all contexts appropriatelly processed. The algorithm is to walk down the hierarchy of the class and aggregate all context filters from its ancestors prioritizing the ones defined earlier in the class hierarchy. The method is working correctly with both parent classes and all Contextualized
mixins used in between.
# File lib/aws/templates/utils/contextualized.rb, line 34 def context @context ||= Filter::Scoped.new(self.class.context, self) end
Enclose block into local context
You can apply additional filters for the block and make it the context of the block so only code in this closure will have defined filter alterations.
# File lib/aws/templates/utils/contextualized.rb, line 44 def contextualize(arg, &blk) if blk clone._set_context(context.scoped_filter & arg).instance_exec(&blk) else Filter::Scoped.new(context.scoped_filter & arg, self) end end
Class-level mixins
It's a DSL extension to declaratively define context filters
# File lib/aws/templates/utils/contextualized.rb, line 64 class_scope do ## # Context filter assigned to the module # # Class-level accessor of a filter to be a part of context. # The method returns only the filter for the current class # without consideration of the class hierarchy. def module_context