ruby-grape / ruby-grape/grape

Should #helpers be class_eval-ing the passed in mod?

Open
#1,634 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug?
Dominant language
Ruby
Stars
10k
Forks
1.2k
Avg merge
14h 38m
Merged PRs (30d)
92

Description

 def helpers(new_mod = nil, &block)
          if block_given? || new_mod
            mod = new_mod || Module.new
            define_boolean_in_mod(mod)
            inject_api_helpers_to_mod(mod) if new_mod

            inject_api_helpers_to_mod(mod) do
              mod.class_eval(&block)
            end if block_given?

            namespace_stackable(:helpers, mod)
          else
            mod = Module.new
            namespace_stackable(:helpers).each do |mod_to_include|
              mod.send :include, mod_to_include
            end
            change!
            mod
          end
        end

mod could be new_mod which means it is having methods injected into it. If you assign something like helpers Some::Poor::ExternalModule it now will get methods included into it from the block due to the mod.class_eval(&block).

Is that correct? This doesn't seem like a side-effect we would want.

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 with the helpers method shown in the issue and trace how new_mod, inject_api_helpers_to_mod, and mod.class_eval interact. Reproduce the behavior with an external module passed to helpers alongside a block, then determine whether modifying that module is intended. Done means the expected behavior is decided and the implementation or regression coverage reflects it.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
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.