Class: Inertia::ProtocolBuilder
- Inherits:
-
Object
- Object
- Inertia::ProtocolBuilder
- Defined in:
- lib/inertia/protocol_builder.rb
Overview
Builds the Inertia page object for a rendered component.
ProtocolBuilder resolves the server-side props hash into the shape expected
by the Inertia protocol. It applies partial reload filtering, evaluates lazy
values, walks nested hashes and arrays, and collects protocol metadata such
as deferredProps and onceProps.
Nested prop paths are tracked with dot notation, e.g. auth.user.name, so
request headers can target either a top-level prop or a nested value.
Instance Method Summary collapse
-
#call ⇒ Hash
Builds the page object hash.
-
#initialize(component, props, context:) ⇒ ProtocolBuilder
constructor
Creates a new protocol builder.
Constructor Details
#initialize(component, props, context:) ⇒ ProtocolBuilder
Creates a new protocol builder.
30 31 32 33 34 35 |
# File 'lib/inertia/protocol_builder.rb', line 30 def initialize(component, props, context:) @props = props @context = context @response = { component:, url: context.url, version: Frontend.version } end |
Instance Method Details
#call ⇒ Hash
Builds the page object hash.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/inertia/protocol_builder.rb', line 40 def call props = resolve_props props[:errors] = EMPTY_ERRORS unless props.has_key?(:errors) @response[:props] = props @response[:deferredProps] = @deferred_props_metadata if @deferred_props_metadata @response[:onceProps] = @once_props_metadata if @once_props_metadata @response end |