Repository navigation
Replace OpenStruct with a lightweight Twitch::Object - #9
Merged
Merged
Conversation
OpenStruct is no longer a default gem, and it's slow to build because it defines singleton methods on every instance. Twitch responses are nested, so every response created many OpenStructs. Twitch::Object now stores attributes in a hash and reads them through method_missing, matching Paddle::Object. Dot access, hash access, setters, nil for missing attributes, dig, each_pair and to_h (with a block) all work as before, and key? has been added. Nested objects and OAuth responses are Twitch::Object rather than OpenStruct, and the ostruct dependency has been removed. Rake is bumped to 13 because rake 12 requires ostruct itself. Building a nested response object is around 17x faster. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
OpenStructwith a hash-backedTwitch::Object, the same implementation asPaddle::Object, minus Paddle'supdate.to_hstill accepts a block.ostructdependency. It's no longer a default gem as of Ruby 4.0.Twitch::OAuthresponses (validate, token requests) now returnTwitch::Objectinstead ofOpenStruct.raketo~> 13.0. Rake 12 requiresostructitself, so tests wouldn't run without it.Compatibility
Dot access, hash access, setters,
dig,each_pair,to_h/to_json/as_jsonand equality work as before, and missing attributes still returnnil. Addskey?. Nested values are nowTwitch::Objectrather thanOpenStruct, which only matters to code that checks the class or callsOpenStruct-specific methods.Performance
Building a nested response (20 items) went from ~518µs to ~31µs per object, roughly 17x faster.
Test plan
bundle exec rake test: 318 runs, 0 failuresbundle exec rubocop: no offensesnilfor missing keys, setters, keys named after built-in methods (type,format,test),dig,each_pair, equality,inspect🤖 Generated with Claude Code