refactor: replace Data.define with ImmutableRecord base class#74
Merged
refactor: replace Data.define with ImmutableRecord base class#74
Conversation
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.
54cc9af to
3a8f2d9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Replaces all 63
Data.definetypes with plain class inheritance from a newImmutableRecordbase class.Why
Data.defineforced us toprependtheMessagemodule (because Data generatesdeconstruct_keyson the class itself, shadowinginclude). 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
ImmutableRecordbase class withattributeDSL,inheritedhook for subclass attribute propagation, structural equality, anddeconstruct_keysthat silently ignores unknown keys (enablingincludefor Message)Data.define(:foo) do ... end→class Foo < ImmutableRecord; attribute :foo; ... endMessagemodule changed fromprependtoinclude< ImmutableRecordinheritance