How to reload a stone for each request in Rails 3.2?

How can I force a reload of a gem for each request?

I am developing a gem and want to reload my gem code every time I refresh a page in a browser. My gemfile:

gem "my_gem", :path => "../my_gem" 

To solve the problem, I tried every sentence specified in stakoverflow. Nothing helped. Two Rails configuration options were also found: watchable_dirs and watchable_files. Tried to use them, but they also do not work for me.

+8
ruby-on-rails
source share
2 answers

You must mark the classes you want to reload as inactive using the unload method ActiveSupport :: Dependencies;

 class YourClass unloadable end 

http://apidock.com/rails/ActiveSupport/Dependencies/Loadable/unloadable and http://robots.thoughtbot.com/post/159805560/tips-for-writing-your-own-rails-engine

should give you some background. Alternatively, you can do your own reboot as follows:

 Object.send(:remove_const, 'YOUR_CLASS') if Object.const_defined?('YOUR_CLASS') GC.start load 'path/to/your_file.rb' 
+2
source share

Ive made a quote of a little hunting around for this, but in the end he took some trial and error.

Library / my_gem / my_gem.rb:

 require 'active_support/dependencies' ActiveSupport::Dependencies.autoload_paths += [File.expand_path("..", __FILE__)] module MyGem include ActiveSupport::Dependencies unloadable end 

Be sure to add "unloadable" to all your classes.

+2
source share

All Articles