Class: Ruact::RenderContext
- Inherits:
-
Object
- Object
- Ruact::RenderContext
- Defined in:
- lib/ruact/render_context.rb
Overview
Per-render mutable state holding the components encountered during ERB evaluation. One instance is allocated by the controller per render, passed explicitly through the pipeline, and discarded when the response is sent.
No shared state, no thread-local lookup — the instance lives only as long as the render call. Satisfies NFR8 and the ‘Ruact/NoSharedState` cop with zero exceptions in `lib/`.
Internal API: not part of the public compatibility contract.
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
Instance Method Summary collapse
- #by_token(token) ⇒ Object
-
#initialize ⇒ RenderContext
constructor
A new instance of RenderContext.
- #register(name, props) ⇒ Object
Constructor Details
#initialize ⇒ RenderContext
Returns a new instance of RenderContext.
14 15 16 |
# File 'lib/ruact/render_context.rb', line 14 def initialize @components = [] end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
18 19 20 |
# File 'lib/ruact/render_context.rb', line 18 def components @components end |
Instance Method Details
#by_token(token) ⇒ Object
26 27 28 |
# File 'lib/ruact/render_context.rb', line 26 def by_token(token) @components.find { |c| c[:token] == token } end |
#register(name, props) ⇒ Object
20 21 22 23 24 |
# File 'lib/ruact/render_context.rb', line 20 def register(name, props) token = "__RUACT_#{@components.length}__" @components << { token: token, name: name, props: props } token end |