Class: Plumb::Codec::Rewriter
- Inherits:
-
Object
- Object
- Plumb::Codec::Rewriter
- Defined in:
- lib/plumb/codec.rb
Overview
The deep rewrite walker. Top-down, per node:
1. Static values, Or/And chains and transparent wrappers recurse into
their parts first — they can carry generator machinery (a
`.default`'s `Undefined >> Static` guard) that a wholesale
replacement would drop (see #visit);
2. a real encoder match replaces the node whole (its input type is
recursively rewritten through the same codec, cycle-guarded);
3. structured composites (Hash schemas, typed Arrays/Tuples/HashMaps)
recurse into their children — AFTER encoder matching, so an encoder
can target a specific composite shape, but BEFORE the noop check,
so a generic `noop Types::Hash` can't swallow a structured schema;
4. decoding, a converting leaf (a Function, a Plumb::Implementation, a
struct) has what it ACCEPTS rewritten through the codec and put in
front of it, so the step is fed the decoded value (see #bridge_input);
5. remaining leaves pass through when noop-covered, otherwise raise with
the dotted field path.
Untouched subtrees keep their identity (the original node is returned), so noop pass-through adds no nodes.
Instance Method Summary collapse
- #call(type) ⇒ Object
-
#initialize(codec, direction) ⇒ Rewriter
constructor
A new instance of Rewriter.
Constructor Details
#initialize(codec, direction) ⇒ Rewriter
Returns a new instance of Rewriter.
230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/plumb/codec.rb', line 230 def initialize(codec, direction) @codec = codec @direction = direction # :decode | :encode @deferred_memo = {}.compare_by_identity @input_memo = {}.compare_by_identity @match_memo = {}.compare_by_identity @noop_memo = {}.compare_by_identity @bridge_memo = {}.compare_by_identity @input_stack = [] @root = nil end |
Instance Method Details
#call(type) ⇒ Object
242 243 244 245 |
# File 'lib/plumb/codec.rb', line 242 def call(type) @root = type visit(type, BLANK_ARRAY) end |