ruby-grape / ruby-grape/grape-entity

Grape::Entity::Delegator::HashObject fails when extracting string keys

Open
#223 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature question
Dominant language
Ruby
Stars
729
Forks
154
PR merge metrics
No merged PRs in 30d

Description

Hi,

I was trying to present a hash of values with a grape entity. The keys in the hash were strings and I got null values all over the place as a response.

It boils down to Grape::Entity::Delegator::HashObject, when it tries to render the attribute it only tries to extract the attribute with a symbol as a key and not a string.

screen shot 2016-05-30 at 13 50 29

I think a simple
object[attribute] || object[attribute.to_s]
would fix the issue, although I'm not sure whether you need to make the destinction between symbols and strings there for other reasons. For now I simple convert all my keys to symbols before handing them to grape entity. But in any case would be more convenient the other way around.

Cheers
Tom

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Grape::Entity::Delegator::HashObject, where attributes are extracted from the presented hash. Reproduce the issue with string-keyed values, then verify that string keys render correctly without breaking symbol-keyed hashes.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.