Skip to content

Unexpected result with Sawyer::Resource #38

@ryz310

Description

@ryz310

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.

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions