Class: Inertia::ProtocolBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/inertia/protocol_builder.rb,
lib/inertia/_codex_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.

Constant Summary collapse

OMITTED =
Object.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(component, props, context:) ⇒ ProtocolBuilder

Creates a new protocol builder.

Parameters:

  • component (String)

    the Inertia component name being rendered

  • props (Hash)

    the props provided by the controller

  • context (RequestContext)

    request-specific partial reload context



26
27
28
29
30
31
# File 'lib/inertia/protocol_builder.rb', line 26

def initialize(component, props, context:)
  @props = props
  @context = context

  @response = { component:, url: context.url, version: Frontend.version }
end

Instance Method Details

#callHash

Builds the page object hash.

Returns:

  • (Hash)

    the Inertia page object payload



36
37
38
39
40
41
42
# File 'lib/inertia/protocol_builder.rb', line 36

def call
  @response[:props] = resolve_props
  @response[:deferredProps] = @deferred_props_metadata if @deferred_props_metadata
  @response[:onceProps] = @once_props_metadata if @once_props_metadata

  @response
end