Unable to mount instances instead of class definitions
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
Grape seems to mostly work when you mount an instance of a class instead of the class definition itself. However, it doesn't actually and uses the instance to find the class definition. This has the side effect that configured classes don't work correctly, and any properties set on them aren't set on the actual controller
As an example:
class DebugController < Grape::API
format :json
def initialize(name)
@name = name
end
desc "No-op that confirms that the service is working"
get '/ping' do
{
:ping => @name
}
end
end
class API < Grape::API
format :json
mount DebugController.new("Test") => "/api/debug"
end
In the above application, when the controller for "/api/debug/ping" is called, the value for "@name" is Nil and not "Test", because the DebugController instance that was passed to mount isn't actually the instance that is used.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Grape's mount handling for the DebugController.new("Test") instance and the /api/debug/ping request in the issue example. Verify which object handles the request and whether @name remains "Test"; done means mounted instances retain their instance state instead of being replaced by a new class-based controller.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100