Skip to content

Replace OpenStruct with a lightweight Twitch::Object - #9

Merged
d34ndev merged 1 commit into
mainfrom
replace-openstruct
Sep 27, 2026
Merged

d34ndev merged 1 commit into
mainfrom
replace-openstruct

Conversation

@d34ndev

@d34ndev d34ndev commented Sep 27, 2026

Copy link
Copy Markdown
Owner

Summary

  • Replaces OpenStruct with a hash-backed Twitch::Object, the same implementation as Paddle::Object, minus Paddle's update. to_h still accepts a block.
  • Removes the ostruct dependency. It's no longer a default gem as of Ruby 4.0.
  • Twitch::OAuth responses (validate, token requests) now return Twitch::Object instead of OpenStruct.
  • Bumps dev dependency rake to ~> 13.0. Rake 12 requires ostruct itself, so tests wouldn't run without it.
  • README and CHANGELOG (Unreleased) updated.

Compatibility

Dot access, hash access, setters, dig, each_pair, to_h/to_json/as_json and equality work as before, and missing attributes still return nil. Adds key?. Nested values are now Twitch::Object rather than OpenStruct, which only matters to code that checks the class or calls OpenStruct-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 failures
  • bundle exec rubocop: no offenses
  • New object tests for hash access, nil for missing keys, setters, keys named after built-in methods (type, format, test), dig, each_pair, equality, inspect

🤖 Generated with Claude Code

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>
@d34ndev
d34ndev merged commit d33d2b8 into main Sep 27, 2026
8 checks passed
@d34ndev
d34ndev deleted the replace-openstruct branch September 27, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant