Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reload a gem on every request in Development mode? [closed]

I've got a Rails app which uses a gem I'm actively developing. How can I instruct the app to reload the gem on every request?

like image 250
Jack Kinsella Avatar asked May 31 '11 18:05

Jack Kinsella


1 Answers

This solution almost works but for some reason I have to put it into application.rb and not in environments/development.rb otherwise the autoload_paths are not recognized.

I added some additional stuff which fetches the paths automagically.

if Rails.env.development?   reload_gems = %w(my_gem other_gem) # names of gems which should autoreload   config.autoload_paths += Gem.loaded_specs.values.inject([]){ |a,gem| a += gem.load_paths if reload_gems.include? gem.name; a }   require 'active_support/dependencies'   ActiveSupport::Dependencies.explicitly_unloadable_constants += reload_gems.map { |gem| gem.classify } end 

Local gems can be added with gem 'my_gem', :path => '../my_gem'

like image 67
Kaworu Avatar answered Sep 22 '22 23:09

Kaworu