JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

prevents the use of attributes that match core functions

Open
#918 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

I'm creating a resource that has a method attribute, but due to the way it works now:

  define_method attr do
    @model.public_send(options[:delegate] ? options[:delegate].to_sym : attr)
  end unless method_defined?(attr)

It fails to work for me. I know method is a core ruby function, but it's also the word used to describe HTTP's GET and PUT.

One option is to simply drop the unless. Allow rewriting, but warn.

Another option is to provide an in and out type option. Currently I would describe delegate as the in, where it describes how to take in the data, and I would provide a key option as the out functionality (what the resulting key will look like).

Contributor guide

No contributing guide indexed for this repository

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 at the resource attribute definition shown in the issue and inspect how method_defined? blocks generated accessors for names such as method. Decide whether collisions should be overwritten with a warning or mapped with an explicit output key, then add regression coverage for the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.