Class: Natsuzora::Payload
- Inherits:
-
Object
- Object
- Natsuzora::Payload
- 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:
-
Adapts host data via the DataNormalizable mixin (Symbol→String keys, whole-number Float→Integer). Pure transformation; never raises.
-
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
-
#data ⇒ Hash
readonly
Adapted and validated root data.
Instance Method Summary collapse
-
#initialize(raw_data) ⇒ Payload
constructor
A new instance of Payload.
Methods included from DataNormalizable
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
#data ⇒ Hash (readonly)
Returns adapted and validated root data.
26 27 28 |
# File 'lib/natsuzora/payload.rb', line 26 def data @data end |