Skip to content

Architecture deepening: FieldRegistry-driven serialization + extractions#16

Merged
ronaldtse merged 1 commit into
mainfrom
fix/architecture-deepening
Jul 23, 2026
Merged

Architecture deepening: FieldRegistry-driven serialization + extractions#16
ronaldtse merged 1 commit into
mainfrom
fix/architecture-deepening

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Three architecture improvements from the codebase review:

1. Entity::Yaml drives from FieldRegistry (Strong)

Replaced the 50-line case entity.type switch with a FieldRegistry-driven approach. from_entity now iterates FieldRegistry.fields_for, reads typed values via the field DSL, and sets YAML attrs by wire_name. This mirrors how Exporters::Json#entity_payload already works.

  • Kills the type switch, KNOWN_WIRE_IDS duplication
  • Fixes MDC_P044 collision bug (code_list vs enumeration_code now type-guarded)
  • Aligned field as: aliases on Property, Unit, Relation, ViewControl

2. NameSynthesizer extracted from SheetSchema (Worth exploring)

NAME_TO_PROPERTY_ID (45 entries) + synthesize() moved to Entity::NameSynthesizer module. SheetSchema delegates. Separate test surface.

3. ImportPipeline extracted from CDDAL Builder (Worth exploring)

process_import, cycle detection, and symbol scoping moved to Cddal::ImportPipeline. Builder delegates. Testable in isolation with in-memory resolver adapter. 4 specs including cycle detection + real import round-trip.

Candidate 4 (bidirectional DSL): Deferred

Write paths already centralized through write_property!; coercion at read time via FieldReader. Marginal benefit doesn't justify risk.

Test plan

  • 69 targeted specs pass (code_quality, model, cddal, name_synthesizer)
  • YAML round-trip: OceanRunner 40→40 entities, powertype preserved
  • Lint: no raw MDC/EXT literals, no respond_to?, no forbidden patterns
  • Net -72 lines (consolidation)

Three architecture improvements from the codebase review:

1. Entity::Yaml drives from FieldRegistry (not a 50-line type switch)
   - from_entity iterates FieldRegistry.fields_for, reads typed values
     via the field DSL, sets YAML attrs by wire_name
   - Eliminates the case entity.type switch, KNOWN_WIRE_IDS duplication
   - Fixes MDC_P044 collision bug (code_list vs enumeration_code now
     type-guarded in to_entity)
   - Aligned field wire_names with YAML attr names via as: aliases
     on Property, Unit, Relation, ViewControl fields

2. NameSynthesizer extracted from SheetSchema
   - NAME_TO_PROPERTY_ID (45 entries) + synthesize() moved to
     Entity::NameSynthesizer module
   - SheetSchema delegates via synthesize_ids_from_names
   - 13 specs covering name synthesis + SheetSchema integration

3. ImportPipeline extracted from CDDAL Builder
   - process_import, check_cycle!, apply_import_scope,
     register_qualified/selective_symbols moved to ImportPipeline
   - Builder delegates apply_import_declarations to it
   - 4 specs with in-memory resolver adapter (no doubles)

Candidate 4 (bidirectional field DSL) deferred: write paths are
already centralized through write_property!, and coercion already
happens at read time via FieldReader. Marginal benefit doesn't
justify the risk of touching core data flow.

Net: -72 lines across modified files. 4 new files (2 lib + 2 spec).
@ronaldtse
ronaldtse merged commit f19e7dd into main Jul 23, 2026
1 check passed
@ronaldtse
ronaldtse deleted the fix/architecture-deepening branch July 23, 2026 04:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant