ruby-grape / ruby-grape/grape-entity

Adding default value to expose

Open
#327 0 comments 0 reactions 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

Is there a way to add a default value to expose in case of the value is not present?
For example

expose :tags do |filter|
  filter[:tags].present? ? filter[:tags] : "all"
end

could be replaced by
expose :tags, default: "all"

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 by locating the expose entry point and the tests covering exposed values. Check how missing values are currently handled and whether option arguments are already supported. Done means expose :tags, default: "all" supplies the default when the value is absent, while existing block-based behavior remains supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.