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

Treat result of to_h to be hashes recursively (support config gem 3+) #1275

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

jrafanie
Copy link
Member

Config gem version 3.0 removed the dot access from .to_h resulting values intentionally. See: https://www.github.com/rubyconfig/config/issues/217

In config 2.2.3, the result of:

Api::ApiConfig.collections.to_h

was:

(byebug) Api::ApiConfig.collections.to_h
{:accounts=>#<Config::Options description="Accounts", options=[:subcollection], verbs=[:get], klass="Account">, :actions=>#<Config::Options description="Actions", identifier="miq_action", options=[:collection], verbs=[:get, :put, :post,
...

With values being Config::Options objects.

In config gem 5.5.2, they're hashes all the way down:

(byebug) Api::ApiConfig.collections.to_h
{:accounts=>{:description=>"Accounts", :options=>[:subcollection], :verbs=>[:get], :klass=>"Account"}, :actions=>{:description=>"Actions", :identifier=>"miq_action", :options=>[:collection], :verbs=>[:get, :put, :post, :patch, :delete],
...

Note, if you don't convert to hash, you retain the Config::Options structure and API:

(byebug) Api::ApiConfig.collections
...

It's easy enough to change the access to assume nested hashes all the way down, which is also compatible with existing Config::Options behavior.

Config gem version 3.0 removed the dot access from .to_h resulting values intentionally.
See: https://www.github.com/rubyconfig/config/issues/217

In config 2.2.3, the result of:

```
Api::ApiConfig.collections.to_h
```

was:

```
(byebug) Api::ApiConfig.collections.to_h
{:accounts=>#<Config::Options description="Accounts", options=[:subcollection], verbs=[:get], klass="Account">, :actions=>#<Config::Options description="Actions", identifier="miq_action", options=[:collection], verbs=[:get, :put, :post,
...
```

With values being Config::Options objects.

In config gem 5.5.2, they're hashes all the way down:

```
(byebug) Api::ApiConfig.collections.to_h
{:accounts=>{:description=>"Accounts", :options=>[:subcollection], :verbs=>[:get], :klass=>"Account"}, :actions=>{:description=>"Actions", :identifier=>"miq_action", :options=>[:collection], :verbs=>[:get, :put, :post, :patch, :delete],
...
```

Note, if you don't convert to hash, you retain the Config::Options structure and API:

```
(byebug) Api::ApiConfig.collections
...
```

It's easy enough to change the access to assume nested hashes all the way down, which is also compatible with existing Config::Options behavior.
@Fryguy
Copy link
Member

Fryguy commented Nov 26, 2024

cc @agrare - Seems the config gem "fixed" the to_hash problem.

@Fryguy Fryguy merged commit fff0961 into ManageIQ:master Nov 26, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants