Skip to content

refactor: replace Data.define with ImmutableRecord base class#74

Merged
htcarr3 merged 1 commit intomainfrom
improvements-032026
Mar 21, 2026
Merged

refactor: replace Data.define with ImmutableRecord base class#74
htcarr3 merged 1 commit intomainfrom
improvements-032026

Conversation

@htcarr3
Copy link
Copy Markdown
Contributor

@htcarr3 htcarr3 commented Mar 21, 2026

What

Replaces all 63 Data.define types with plain class inheritance from a new ImmutableRecord base class.

Why

Data.define forced us to prepend the Message module (because Data generates deconstruct_keys on the class itself, shadowing include). It also meant RBS signatures had no real supertype — every type was a standalone class. The base class is ~50 lines, eliminates the prepend hack, and makes the type hierarchy explicit.

How

  • New ImmutableRecord base class with attribute DSL, inherited hook for subclass attribute propagation, structural equality, and deconstruct_keys that silently ignores unknown keys (enabling include for Message)
  • Mechanical migration: Data.define(:foo) do ... endclass Foo < ImmutableRecord; attribute :foo; ... end
  • Message module changed from prepend to include
  • RBS signatures updated with < ImmutableRecord inheritance
  • Net -65 lines (573 added, 638 removed across 32 files)
  • All 1234 tests pass, RBS validates, RuboCop clean — zero test changes needed

Introduces a plain-inheritance ImmutableRecord base class with an
`attribute` DSL, replacing all 63 Data.define types. This eliminates
the prepend hack for the Message module, gives real supertype
inheritance for RBS signatures, and centralizes freeze/equality/
pattern-matching in one transparent ~50-line class.
@htcarr3 htcarr3 force-pushed the improvements-032026 branch from 54cc9af to 3a8f2d9 Compare March 21, 2026 12:43
@htcarr3 htcarr3 merged commit 3be7174 into main Mar 21, 2026
1 check passed
@htcarr3 htcarr3 deleted the improvements-032026 branch March 21, 2026 12:43
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