Class: Sourcerer::Templating::Context
- Inherits:
-
Object
- Object
- Sourcerer::Templating::Context
- Defined in:
- lib/sourcerer/templating.rb
Overview
Holds contextual information for templating.
Instance Attribute Summary collapse
-
#scopes ⇒ Hash
readonly
A hash of scopes for rendering.
-
#stage ⇒ Symbol
readonly
The rendering stage (e.g.,
:load). -
#strict ⇒ Boolean
readonly
Whether to use strict rendering.
Class Method Summary collapse
-
.from_schema(schema_fragment) ⇒ Context
Creates a new Context object from a schema fragment.
Instance Method Summary collapse
-
#initialize(stage: :load, strict: false, scopes: {}) ⇒ Context
constructor
A new instance of Context.
-
#merged_scope ⇒ Hash
Merges all scopes into a single hash.
Constructor Details
#initialize(stage: :load, strict: false, scopes: {}) ⇒ Context
Returns a new instance of Context.
124 125 126 127 128 |
# File 'lib/sourcerer/templating.rb', line 124 def initialize stage: :load, strict: false, scopes: {} @stage = stage.to_sym @strict = strict @scopes = scopes.transform_keys(&:to_sym) end |
Instance Attribute Details
#scopes ⇒ Hash (readonly)
Returns A hash of scopes for rendering.
119 120 121 |
# File 'lib/sourcerer/templating.rb', line 119 def scopes @scopes end |
#stage ⇒ Symbol (readonly)
Returns The rendering stage (e.g., :load).
115 116 117 |
# File 'lib/sourcerer/templating.rb', line 115 def stage @stage end |
#strict ⇒ Boolean (readonly)
Returns Whether to use strict rendering.
117 118 119 |
# File 'lib/sourcerer/templating.rb', line 117 def strict @strict end |
Class Method Details
.from_schema(schema_fragment) ⇒ Context
Creates a new Context object from a schema fragment.
133 134 135 136 137 138 139 140 141 |
# File 'lib/sourcerer/templating.rb', line 133 def self.from_schema schema_fragment render_conf = schema_fragment['templating'] || {} stage = (render_conf['stage'] || :load).to_sym strict = render_conf['strict'] == true scopes = (render_conf['scopes'] || {}).transform_keys(&:to_sym) new(stage: stage, strict: strict, scopes: scopes) end |
Instance Method Details
#merged_scope ⇒ Hash
Merges all scopes into a single hash.
145 146 147 |
# File 'lib/sourcerer/templating.rb', line 145 def merged_scope scopes.values.reduce({}) { |acc, s| acc.merge(s) } end |