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

Unexpected result with Sawyer::Resource #38

Open
ryz310 opened this issue Jun 4, 2019 · 1 comment
Open

Unexpected result with Sawyer::Resource #38

ryz310 opened this issue Jun 4, 2019 · 1 comment
Assignees
Labels
wontfix This will not be worked on

Comments

@ryz310
Copy link
Owner

ryz310 commented Jun 4, 2019

An API is expected to return following result.

{
  "age_range": {
    "max": 30,
    "min": 20
  }
}

An instance which implemented with MyApiClient returns that result as Sawyer::Resource.

result = ApiClient.request
result[:max] # => 30

However, if the API returns following result, above execution will unexpected result.

{
  "age_range": {
    "min": 20
  }
}
result = ApiClient.request
result[:max] # => [:min, 20]

The cause is into the Sawyer::Resouce implementation. Sawyer::Resouce#[] calls #method_missing and searches the key from inner fields.
Ordinarily it will return nil if does not find the key.

However, :max is Enumerable module instance so it will happen that calls Enumerable#max method.

@ryz310 ryz310 self-assigned this Jun 4, 2019
@ryz310 ryz310 added the bug Something isn't working label Jun 4, 2019
@ryz310
Copy link
Owner Author

ryz310 commented Jun 6, 2019

I reported. lostisland/sawyer#64

@ryz310 ryz310 added wontfix This will not be worked on and removed bug Something isn't working labels Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant