You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks @dblock for the example on how to use Grape on Goliath.
But I found that this example could not autoload modified files in development mode. And I tried a simpler approach like this: https://gist.github.com/larryzhao/7913394 , after I modified the api, I could see the Rack::Reloader is trigger to load the file, but the response is still the same.
But grape-on-rails works just fine. Is there anything I need to configure in Grape to achieve that?
@dblock@larryzhao I was able to get this to work in my own project. Instead of manually requiring your development files, you need to have them autoloaded. Active Support has nice exposure for this.
You need active_support/dependencies
require 'active_support/dependencies'
Select the directories you want constants autoloaded from
class Server < Goliath::API
def response(env)
Base.call(env)
end
def on_close(env)
if Goliath.env == :development
ActiveSupport::Dependencies::clear
end
end
end
Once the connection has closed for a Fiber it should reload just your application code. Atleast it's been working for me. Hope this helps.
@skydan Sorry, I haven't had time to merge this into this repo. I started a new project with Goliath and Grape, without using this structure. However, I did see this issue when I was looking at examples, thus my update when I got it working. I've now dropped Goliath and Grape and have moved to something different.
@skydan Note the project is a bit out of whack. You can look at https://github.com/patbaker82/grape_juice/blob/master/lib/grape_juice.rb specifically and you can basically put that into the application.rb in this project. All in all its pretty simple. You just need to autoload the dependencies with active support and modify the Goliath on_close event.
Yes, I've added my dependencies in autoload_paths and also on_close event triggers Activesupport::Dependency.clear as expected. But unfortunately this is doesn't affect reloading api modules and classes.
Is the on_close event firing? Can you put a logger/puts statement in there? You would also need to make sure that the paths that are in autoload_paths are relative to where the application thinks it is. I would put the full path in to see if that helps and then figure out the relative bit later.
Hmm, loaded and autoloaded_constants are empty during clear method call. But relative_load_paths looks like correct. What should I do to populate loaded?
Implemented in #5. Grape retains compiled routes and references to mounted API classes, so Rack::Reloader can reload a file while requests still use the old routes. The proposed development command, bundle exec rerun -- ruby app.rb -sv -e development, watches application Ruby files and restarts the server instead; normal startup is unchanged.
A real HTTP regression verifies that editing an API changes its route and response and removes the old route. All hosted Ruby/Goliath matrix jobs, lint, and coverage pass. This issue will close when #5 merges.
Activity
dblock commentedon Dec 12, 2013
TBH I couldn't fix it.
wolfie82 commentedon Jun 15, 2014
@dblock @larryzhao I was able to get this to work in my own project. Instead of manually requiring your development files, you need to have them autoloaded. Active Support has nice exposure for this.
Once the connection has closed for a Fiber it should reload just your application code. Atleast it's been working for me. Hope this helps.
dblock commentedon Jun 15, 2014
@patbaker82 Would you mind PR-ing this into this project? Much appreciated.
dblock commentedon Jun 15, 2014
And also a README update to https://github.com/intridea/grape
wolfie82 commentedon Jun 15, 2014
@dblock No problem, however I will likely get to it tomorrow.
skydan commentedon Jun 20, 2014
@patbaker82, is there any chance to see your solution in action?
wolfie82 commentedon Jun 20, 2014
@skydan Sorry, I haven't had time to merge this into this repo. I started a new project with Goliath and Grape, without using this structure. However, I did see this issue when I was looking at examples, thus my update when I got it working. I've now dropped Goliath and Grape and have moved to something different.
I committed https://github.com/patbaker82/grape_juice which shows how I had it working.
wolfie82 commentedon Jun 20, 2014
@skydan Note the project is a bit out of whack. You can look at https://github.com/patbaker82/grape_juice/blob/master/lib/grape_juice.rb specifically and you can basically put that into the application.rb in this project. All in all its pretty simple. You just need to autoload the dependencies with active support and modify the Goliath on_close event.
skydan commentedon Jun 20, 2014
Yes, I've added my dependencies in
autoload_pathsand alsoon_closeevent triggersActivesupport::Dependency.clearas expected. But unfortunately this is doesn't affect reloading api modules and classes.wolfie82 commentedon Jun 20, 2014
Is the on_close event firing? Can you put a logger/puts statement in there? You would also need to make sure that the paths that are in autoload_paths are relative to where the application thinks it is. I would put the full path in to see if that helps and then figure out the relative bit later.
wolfie82 commentedon Jun 20, 2014
@skydan I would also look at https://github.com/rails/docrails/blob/master/activesupport/lib/active_support/dependencies.rb
You can print out what's in Activesupport::Dependency.loaded() and autoloaded_constants() to see if they've even been loaded.
skydan commentedon Jun 20, 2014
Hmm,
loadedandautoloaded_constantsare empty duringclearmethod call. But relative_load_paths looks like correct. What should I do to populateloaded?wolfie82 commentedon Jun 20, 2014
@skydan I can't see the gist
skydan commentedon Jun 20, 2014
I've fixed the link.
wolfie82 commentedon Jun 20, 2014
@skydan It's interesting to point out that the files wont be "loaded" until they're needed.
Also I would try:
etc
dblock commentedon Oct 27, 2026
Implemented in #5. Grape retains compiled routes and references to mounted API classes, so Rack::Reloader can reload a file while requests still use the old routes. The proposed development command,
bundle exec rerun -- ruby app.rb -sv -e development, watches application Ruby files and restarts the server instead; normal startup is unchanged.A real HTTP regression verifies that editing an API changes its route and response and removes the old route. All hosted Ruby/Goliath matrix jobs, lint, and coverage pass. This issue will close when #5 merges.
AI posting on behalf of @dblock.