Skip to content

refactor: type-driven dispatch with marker modules and registry pattern#307

Merged
ronaldtse merged 7 commits into
mainfrom
rt-tmp
Jun 5, 2026
Merged

refactor: type-driven dispatch with marker modules and registry pattern#307
ronaldtse merged 7 commits into
mainfrom
rt-tmp

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

Replaces runtime type introspection (method_defined?, respond_to?, send) with explicit marker modules and registry-based dispatch throughout the codebase.

Changes

Marker modules (Model::Concerns)

  • HasId — included by Identifier, ExpFile, InterfacedItem, InterfaceItem, RemarkItem
  • HasRemarks, HasRemarkItems — included by relevant declaration types

Registry-based formatter dispatch

  • FORMATTER_REGISTRY hash maps model classes to handler modules
  • Each formatter module registers handlers via register_formatter
  • Eliminates large case/when chains in Formatter and PrettyFormatter

COLLECTION_REGISTRY in remark_attacher

  • Per-type hash maps model classes to their collection attributes
  • Replaces 18-attribute respond_to?/send probing on every node
  • EXPRESSION_CHILDREN registry for targeted query expression traversal

Other improvements

  • ModelElement#path uses is_a?(HasId) instead of method_defined?(:id)
  • Repository#restore_indexes replaces instance_variable_set
  • Package::Reader uses public API instead of ivar manipulation
  • Builder qualifier returns IndexReference instead of Hash

Testing

  • 1395 examples, 0 failures, 4 pending (known parser grammar limitations)
  • New formatter_architecture_spec.rb validates registry and marker module behavior
  • New roundtrip specs for AGGREGATE OF, CONSTANT, syntax.exp patterns

ronaldtse added 6 commits May 20, 2026 22:39
- Add HasId, HasRemarks, HasRemarkItems marker modules in concerns.rb
- Identifier auto-includes HasId
- ModelElement#path uses is_a?(HasId) instead of method_defined?(:id)
- ModelElement uses public_send instead of send
- ExpFile includes HasId for correct path computation
- InterfaceItem, InterfacedItem, RemarkItem include HasId
- Schema children uses explicit interfaced_items method
- Formatter uses FORMATTER_REGISTRY for type-to-handler mapping
- Each formatter module registers handlers via register_formatter
- Removed private visibility from formatter module methods
- HyperlinkFormatter and SchemaHeadFormatter use <= inheritance check
- PrettyFormatter simplified with registry dispatch
…_attacher

- COLLECTION_REGISTRY maps model types to collection attributes
- EXPRESSION_CHILDREN maps expression/statement types for query traversal
- collect_children and calculate_children_end_line use registry
- find_query_in_expression uses targeted traversal
- Builder qualifier returns IndexReference instead of Hash
- coverage.rb uses is_a?(HasRemarks), is_a?(HasRemarkItems), is_a?(HasId)
- Repository#restore_indexes replaces instance_variable_set usage
- Package::Reader uses public API instead of ivar manipulation
- formatter_architecture_spec.rb tests registry dispatch, marker modules
- formatter_roundtrip_spec.rb adds AGGREGATE OF, CONSTANT, syntax.exp tests
- unique_rule_spec.rb fixes be_empty to be_nil
@ronaldtse ronaldtse force-pushed the rt-tmp branch 2 times, most recently from 38b4ab9 to 571a6c3 Compare June 5, 2026 10:37
@ronaldtse ronaldtse merged commit 14d5853 into main Jun 5, 2026
16 checks passed
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