Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Refactor internal command data classes #358

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Nov 25, 2024

The new CommandData superclass uses Data (prereq: #352) to add the pattern matching and equality methods while also simplifying the implementation. Specifically, I wanted RawData#deconstruct for the basic ESEARCH support branch (#333). It seemed reasonable to apply the same change to all of the internal command data classes.

Please note: this does change these objects to be frozen. However, these classes are explicitly undocumented (:nodoc), never returned by any public methods, and considered "internal", so this will not be treated as a "breaking change". I've extracted this from #333 into its own PR purely for documentation (release notes, etc).

nevans and others added 2 commits November 25, 2024 12:08
For new data structs, I don't want to commit to supporting the entire
Struct API and I'd prefer frozen by default.  `Data` is exactly what I
want but it's not available until ruby 3.2.

So this adds a DataLite class that closely matches ruby 3.2's Data
class and can be a drop-in replacement for Data.  Net::IMAP::Data is an
alias for Net::IMAP::DataLite, so when we remove this implementation,
the constant will resolve to ruby's ::Data.  The most noticable
incompatibility is that member names must be valid local variable names.

Ideally, we wouldn't define this on newer ruby versions at all, but that
breaks the YAML serialization for our test fixtures.  So, on newer
versions of ruby, this class inherits from `Data` and only reimplements
the two methods that are needed for YAML serialization.  This serves the
additional purpose of ensuring that the same tests pass for both the
core `Data` class and our reimplementation.

Most of the test code and some of the implementation code has been
copied from the polyfill-data gem and updated so that they use "Data" as
it is resolved inside the "Net::IMAP" namespace.  Copyright notices have
been added to the appropriate files to satisfy the MIT license terms.

Co-authored-by: Jim Gay <[email protected]>
The new `CommandData` superclass uses `Data` to add the pattern matching
and equality methods while also simplifying the implementation.

Specifically, I wanted RawData#deconstruct for the basic `ESEARCH`
support branch.  It seemed reasonable to apply the same change to all of
the internal command data classes.

Please note: this does change these objects to be frozen.  However,
these classes are explicitly undocumented and considered "internal", so
this will _not_ be treated as a "breaking change".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant