Replace OpenStruct with hash-backed Context (v4.0.0)#225
Open
crisnahine wants to merge 2 commits intocollectiveidea:masterfrom
Open
Replace OpenStruct with hash-backed Context (v4.0.0)#225crisnahine wants to merge 2 commits intocollectiveidea:masterfrom
crisnahine wants to merge 2 commits intocollectiveidea:masterfrom
Conversation
- Assert Context.superclass == Object (currently fails — inherits OpenStruct) - Replace internal send(:table) test with public to_h assertion
Interactor::Context no longer inherits from OpenStruct, which is deprecated in Ruby 3.2+ and may be removed in a future Ruby version. The replacement is a plain hash-backed implementation that preserves the full public API with no runtime dependencies. Breaking changes (major version bump to 4.0.0): - context.is_a?(OpenStruct) now returns false - OpenStruct-only methods (each_pair, marshal_dump, etc.) are gone All documented public API is unchanged: - Dynamic attribute accessors (context.foo, context.foo = val) - Bracket access ([], []=) with symbol/string key normalization - to_h, ==, inspect, to_s, fail!, success?, failure?, rollback! - deconstruct_keys for Ruby 3.0+ pattern matching Also fixes a StandardRB identity comparison warning in Interactor#run.
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.
Summary
Interactor::Context < OpenStructwith a plain hash-backed implementationostructruntime dependency entirely4.0.0(semver major — breaking change)Motivation
OpenStructwas deprecated in Ruby 3.2+ and may be removed in a future Ruby version. This change eliminates the deprecation warning and future-proofs the gem with zero runtime dependencies.What changed
lib/interactor/context.rbContextnow inherits fromObjectinstead ofOpenStruct@tablestore withmethod_missingfor dynamic accessors[],[]=,to_h,==,inspect,to_sexplicitlyHash#each, nottransform_keys)interactor.gemspecspec.add_dependency "ostruct"4.0.0lib/interactor.rbLint/IdentityComparisonwarning (object_id !=→!equal?)spec/interactor/context_spec.rbContext.superclass == Objectto lock in the new contractsend(:table)internal accessor test to use publicto_hBreaking changes
context.is_a?(OpenStruct)now returnsfalseeach_pair,marshal_dump,marshal_load) are no longer availableMigration: If your code does not check
is_a?(OpenStruct)or call OpenStruct-specific methods, no changes are required.Test results