ruby-grape / ruby-grape/grape-entity

Custom Entity options support

Open
#382 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

It would be great to be able to provide custom options for entity exposure like:

expose :name, custom: { key: 'value' }

Not only option named custom but any other name as well. It might be helpful sometimes

Now such custom options not allowed ant an exception is throwing:

/gems/grape-entity-1.0.0/lib/grape_entity/entity.rb:624:in `block in valid_options': :custom is not a valid option. (ArgumentError):

 raise ArgumentError, "#{key.inspect} is not a valid option." unless OPTIONS.include?(key)

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 lib/grape_entity/entity.rb at valid_options, around line 624, and review how expose options are validated. Reproduce the shown :custom ArgumentError, then determine how arbitrary named options should be accepted for entity exposure; done means the example and other option names no longer raise that validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 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.