ruby-grape / ruby-grape/grape-entity

Safe behavior (question)

Open
#285 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hi folks. Given the following entity:

expose :name
expose :address
  expose :street, safe: true do |instance, _|
    instance.address.street
  end
end

If address is nil, safe: true is supposed to make street return nil instead of an exception? It's returning undefined method street for nil:NilClass.

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

Reproduce the Ruby entity example from the issue first, then locate the implementation and tests for the safe option. Confirm whether safe: true is intended to guard the nested instance.address.street call; done when the expected behavior is established and covered by a regression test or the issue is clarified.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.