Class: Loom::Pattern::DefinitionContext
- Inherits:
-
Object
- Object
- Loom::Pattern::DefinitionContext
- Defined in:
- lib/loom/pattern/definition_context.rb
Overview
Pattern::DefinitionContext is the collection of facts, hooks, and parent contexts a pattern is defined along side of. The context includes all contexts of parent modules.
Instance Attribute Summary collapse
-
#fact_map ⇒ Object
readonly
Returns the value of attribute fact_map.
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#let_map ⇒ Object
readonly
Returns the value of attribute let_map.
Instance Method Summary collapse
- #after_hooks ⇒ Object
- #before_hooks ⇒ Object
-
#define_let_readers(scope_object, fact_set) ⇒ Object
TODO: #define_let_readers is a TERRIBLE name.
-
#fact_set(host_fact_set) ⇒ Object
Merges the facts defined by the pattern context with the host fact_set.
-
#initialize(pattern_module, parent_context = nil) ⇒ DefinitionContext
constructor
A new instance of DefinitionContext.
Constructor Details
#initialize(pattern_module, parent_context = nil) ⇒ DefinitionContext
Returns a new instance of DefinitionContext.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/loom/pattern/definition_context.rb', line 9 def initialize(pattern_module, parent_context=nil) @fact_map = pattern_module.facts.dup @let_map = pattern_module.let_map.dup @hooks = pattern_module.hooks.dup @parent_context = parent_context @merged_fact_map = merged_fact_map @merged_let_map = merged_let_map end |
Instance Attribute Details
#fact_map ⇒ Object (readonly)
Returns the value of attribute fact_map.
20 21 22 |
# File 'lib/loom/pattern/definition_context.rb', line 20 def fact_map @fact_map end |
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
20 21 22 |
# File 'lib/loom/pattern/definition_context.rb', line 20 def hooks @hooks end |
#let_map ⇒ Object (readonly)
Returns the value of attribute let_map.
20 21 22 |
# File 'lib/loom/pattern/definition_context.rb', line 20 def let_map @let_map end |
Instance Method Details
#after_hooks ⇒ Object
48 49 50 |
# File 'lib/loom/pattern/definition_context.rb', line 48 def after_hooks Hook.after_hooks merged_hooks.reverse end |
#before_hooks ⇒ Object
44 45 46 |
# File 'lib/loom/pattern/definition_context.rb', line 44 def before_hooks Hook.before_hooks merged_hooks end |
#define_let_readers(scope_object, fact_set) ⇒ Object
TODO: #define_let_readers is a TERRIBLE name. Rename this method.
The method is called by Reference#call with the Reference::RunContext instance. The “let” defined local declarations are added as method definitions on each RunContext instance. The @merged_let_map is the map of let definitions, merged from the associated module, up the namespace graph, allowing for inheriting and overriding let declarations.
36 37 38 39 40 41 42 |
# File 'lib/loom/pattern/definition_context.rb', line 36 def define_let_readers(scope_object, fact_set) @merged_let_map.each do |let_key, block| raise "no let block" unless block value = scope_object.instance_exec fact_set, &block scope_object.define_singleton_method(let_key) { value } end end |
#fact_set(host_fact_set) ⇒ Object
Merges the facts defined by the pattern context with the host fact_set
25 26 27 |
# File 'lib/loom/pattern/definition_context.rb', line 25 def fact_set(host_fact_set) host_fact_set.merge merged_fact_map end |