Class: Natsuzora::Payload

Inherits:
Object
  • Object
show all
Includes:
DataNormalizable
Defined in:
lib/natsuzora/payload.rb

Overview

Wraps raw host data prepared for a single Template#render call.

The class is the explicit boundary between untrusted host data (Symbol-keyed Hashes, host-side numeric types, etc.) and the value space that Renderer and Context consume.

On construction:

  1. Adapts host data via the DataNormalizable mixin (Symbol→String keys, whole-number Float→Integer). Pure transformation; never raises.

  2. Asserts conformance to Natsuzora’s value type system via Validator.validate_data!. Raises TypeError on any residual violation (Float left over, Integer outside the safe range, NaN/Infinity).

If ‘new` returns, `#data` is guaranteed to conform; downstream components trust the result without further validation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataNormalizable

#normalize_data

Constructor Details

#initialize(raw_data) ⇒ Payload

Returns a new instance of Payload.



28
29
30
31
32
33
# File 'lib/natsuzora/payload.rb', line 28

def initialize(raw_data)
  raise Natsuzora::TypeError, 'Root data must be an object' unless raw_data.is_a?(Hash)

  @data = normalize_data(raw_data)
  Validator.validate_data!(@data)
end

Instance Attribute Details

#dataHash (readonly)

Returns adapted and validated root data.

Returns:

  • (Hash)

    adapted and validated root data



26
27
28
# File 'lib/natsuzora/payload.rb', line 26

def data
  @data
end