Module: Ruact::ServerFunctions::BucketTwoPayload

Defined in:
lib/ruact/server_functions/bucket_two_payload.rb

Overview

Story 9.2 — pure serializer for the Bucket-2 (imperative ‘await fn()`) response body. Takes the host action’s exposed instance variables (Rails ‘view_assigns`, resolved by the caller) and produces a JSON-ready Ruby Hash, keyed by ivar name, applying the SAME prop-exposure policy as the Flight serializer (Flight::Serializer#serialize_unknown):

- {Ruact::Serializable} values expose ONLY their `ruact_props` (secrets
  never leak), recursing into nested Serializables / collections.
- Under `strict_serialization`, a non-Serializable domain object raises
  {Ruact::SerializationError} (no accidental full-record dump).
- Otherwise a vetted `as_json` fallback applies (guards against
  `as_json` returning self / raising).

Unlike the Flight serializer this produces PLAIN JSON-ready values (Hash / Array / scalar) — ‘render json:` does the final encoding, so JSON primitives (incl. Time/Date) pass through untouched rather than being Flight-encoded.

Pure — no Rails / request / ‘Ruact.config` reads. The caller resolves the exposed-ivar set and the `strict` flag (mirroring the ErrorPayload caller/builder split, NFR26 / AC8).

Class Method Summary collapse

Class Method Details

.build(assigns, strict:) ⇒ Hash{String=>Object}

Returns JSON-ready hash keyed by ivar name.

Parameters:

  • assigns (Hash)

    exposed-ivar name (String, no ‘@`) => value

  • strict (Boolean)

    the resolved ‘strict_serialization` mode

Returns:

  • (Hash{String=>Object})

    JSON-ready hash keyed by ivar name

Raises:



43
44
45
# File 'lib/ruact/server_functions/bucket_two_payload.rb', line 43

def build(assigns, strict:)
  assigns.to_h { |name, value| [name.to_s, serialize(value, strict)] }
end

.serialize_value(value, strict:) ⇒ Object

Story 9.4 (D6) — the per-value branch of the policy, extracted so the query dispatch controller serializes a method’s single RETURN VALUE (Array / Hash / scalar / Serializable / nil) through the exact rules build applies to each exposed ivar. One policy, two callers.

Parameters:

  • value (Object)

    the query method’s return value

  • strict (Boolean)

    the resolved ‘strict_serialization` mode

Returns:

  • (Object)

    JSON-ready value (‘nil` stays `nil` → JSON `null`)

Raises:



56
57
58
# File 'lib/ruact/server_functions/bucket_two_payload.rb', line 56

def serialize_value(value, strict:)
  serialize(value, strict)
end