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

Wrap YAML in Hashie::Mash #26

Merged
merged 1 commit into from
May 17, 2022
Merged

Wrap YAML in Hashie::Mash #26

merged 1 commit into from
May 17, 2022

Conversation

adsteel
Copy link
Contributor

@adsteel adsteel commented Apr 27, 2022

Resolves #25

Problem

Setting had different behavior depending on the access pattern. Sometimes it was more forgiving than Ruby, other times it was not.

Setting[:foo] # yes
Setting['foo'] # yes
Setting.foo('bar') # yes
Setting.foo(:bar) # yes
Setting.foo['bar'] # yes

Setting.foo[:bar] # no, returns `nil`

Solution

By wrapping the YAML in Hashie::Mashie, we can avoid breaking any existing tests while improving the behavior consistency. Because this may break how folks are using the gem, it should be released as a breaking change.

`Setting` had different behavior depending on the access pattern.
Sometimes it was more forgiving than Ruby, other times it was not.

```ruby
Setting[:foo] # bar
Setting['foo'] # bar
Setting.foo('bar') # baz
Setting.foo(:bar) # baz
Setting.foo['bar'] # baz
Setting.foo[:bar] # nil
```

By wrapping the YAML in Hashie::Mashie, we can avoid breaking any
existing tests while improving the behavior consistency.
@adsteel adsteel requested a review from a team as a code owner April 27, 2022 22:52
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_dependency "hashie"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hesitant to add this dependency to every app that uses fittings. Is this bug something that can be fixed without it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be, yes. We would have to either globally monkey patch Hash or recursively wrap each object in an enhanced hash, which is essentially what Hashie::Mash is doing for us. The tradeoffs with those approaches being that we avoid a new dependency, but incur supporting similar complex logic on our own (the recursive logic) or extend our monkey patching of a core Rails class. I personally think we should avoid monkey patching Ruby classes due to the risk that can bring. Too much depends on them for us to be tweaking them on our own.

I can see the arguments for the recursive option and this option. I lean toward this approach because it minimizes our future support needs for this gem, but I'm definitely open on the issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a data point: per appetizer, it looks like every app that uses fittings already uses hashie as well. There may be a flaw in my method, posting here for review/scrutiny:

appetizer -g hashie | jq -r keys[] > hashie
appetizer -g fittings | jq -r keys[] > fittings
comm -23 fittings hashie
# no output, meaning no lines unique to "fittings"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I don't want to block progress here. I've seen dependencies prevent upgrades to Rails and Ruby. And every dependency is an extra download for everyone.

But if everyone already needs it... this is probably fine.

Copy link
Contributor

@bak bak May 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be giving late feedback—I hinted at this in slack, but api_client gem will always pull in hashie as a dependency (for backwards-compatibility with code that was written with the version that used hashie), but it's very common to configure subclasses or other uses to use plain hashes instead, so teams are able to opt-in to Hashie's performance impact.

That's not to say there aren't apps actually using hashie, but I don't think appetizer is answering the right question for us.

Copy link
Contributor

@ebarendt ebarendt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the changelog, too!

@adsteel
Copy link
Contributor Author

adsteel commented May 6, 2022

@ebarendt @zackse what's the protocol at this point? Should I merge, bump the version number in another PR, and do a release myself?

@zackse
Copy link
Contributor

zackse commented May 6, 2022

@adsteel adsteel merged commit 941686e into main May 17, 2022
@adsteel adsteel deleted the ags/switch-to-mashie branch May 17, 2022 15:42
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.

Unexpected [] behavior compared to other access patterns
4 participants