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

What happens if we recursively map hashes in response to StrictOpenStuct? #135

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tom-lord
Copy link
Member

This could prevent weird inconsistencies like this:

oo = RestfulResource::OpenObject.new({foo: :bar, baz: {nested: 123}})
#=> #<RestfulResource::OpenObject:0x000055dba392ab38 @inner_object=#<RestfulResource::StrictOpenStruct foo=:bar, baz={:nested=>123}>>

oo.foo #=> :bar
oo.baz #=> {nested: 123}
oo.baz.nested #=> UNDEFINED METHOD ON HASH
oo.baz[:nested] #=> 123

oo[:baz] #=> DEPRECATION WARNING

However, I'm concerned that this could be a breaking change in some cases due to:

NoMethodError: undefined method `fetch' for #<RestfulResource::OpenObject:0x000055dba392ab38>

...Maybe we'd also need to make :fetch call send for compatibility??!

@tom-lord
Copy link
Member Author

tom-lord commented May 14, 2021

Actually, I think this might be a misunderstanding... Should we be using has_one / has_many for scenarios like this?? https://github.com/carwow/restful_resource/blob/master/lib/restful_resource/associations.rb

However I think this is causing inconsistency where we use the library in not-so-restful ways, e.g. https://github.com/carwow/dealers_site/blob/master/api_client/lib/dealers_site_api_client/promotion.rb -- because you cannot really declare a has_one relationship when the response format varies so much??

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.

None yet

1 participant