Replace OpenStruct with hash-backed Context (v4.0.0)#225
Open
crisnahine wants to merge 1 commit into
Open
Conversation
|
Having this would also make the gem much faster as OpenStruct is known to have performance issues. |
OpenStruct is deprecated on Ruby 3.2+ and leaves the default gems in Ruby 4.0. Reimplement Interactor::Context as a plain hash-backed object and drop the ostruct runtime dependency. - Context inherits from Object and stores attributes in an @table hash with method_missing accessors. All documented public API is preserved: build, [], []=, to_h, ==, success?, failure?, fail!, called!, rollback!, _called, deconstruct_keys, and dynamic getters/setters. - respond_to_missing? reports true only for setters and already-set keys, so the context never advertises implicit conversions (to_ary/to_hash/to_str) that method_missing would answer with nil. - initialize_copy gives dup/clone an independent store instead of aliasing the original's hash. - A reader called with arguments raises ArgumentError, matching a real zero-arity accessor. - Bump the version to 4.0.0. Breaking: Context is no longer is_a?(OpenStruct) and OpenStruct-only methods (each_pair, marshal_dump, marshal_load) are gone. - Fix the Lint/IdentityComparison warning in Interactor#run. 118 examples, 0 failures; standardrb clean.
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