2

I am trying to have a plugin I am developing auto-reload every time I change my code, emulating the same auto-reloading that happens normally in Rail's development mode. My plugin is primarily an ActiveRecord mixin module. I have tried all suggestions I have been able to find in related Google searches. Nothing has worked yet.

In my plugin's init.rb:

require 'activesupport' unless defined? ActiveSupport
require 'activerecord' unless defined? ActiveRecord

if RAILS_ENV == 'development'
    ActiveSupport::Dependencies.load_once_paths.delete lib_path
    ActiveSupport::Dependencies.load_once_paths.delete File.join(lib_path, 'crowd_compass', 'publisher.rb')

    ActiveSupport::Dependencies.load_paths << lib_path
    ActiveSupport::Dependencies.load_paths << File.join(lib_path, 'crowd_compass', 'publisher.rb')
end

ActiveRecord::Base.send(:include, CrowdCompass::Publisher)

Looking in the rails changelog, I did notice the feature to auto reload all plugins.

config.reload_plugins = true if RAILS_ENV == 'development'

This did not work as I expected it to when I added it to my conf/environment.rb

My plugin is structured so all files are auto-loaded by namespace => directory. I did this so I could avoid using "require", as I thought require was inhibiting my plugin from being auto-reloaded.

I have been doing all of my work in development mode through the rails console and I do not know if this behaves any different than running through mongrel (or like web server).

The plugin works as expected, but I have to reload every time I make any change to the code. Does anyone know a way to get plugins to reload?

Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261
Sean McCleary
  • 3,690
  • 4
  • 33
  • 43

1 Answers1

1

The console definitely doesn't work like a mongrel. All of the techniques you're using are made to reload on every request, which is akin to every time you start up the console.

There isn't a way to reload code in the console without calling reload!.

BJ Clark
  • 3,215
  • 2
  • 17
  • 16
  • That is what I was afraid of. I would have even been happy with reload!, but that did not work out for me either. Instead, I have to completely restart the console every time I change anything in my plugin. Plugin development would be easier if this was addressed. Thank you for your reply. – Sean McCleary Oct 28 '09 at 01:34
  • Have you tried writing tests? If you test drove your plugin, you wouldn't have to reload the console so much. – BJ Clark Oct 28 '09 at 05:39
  • 1
    @BJ Clark. A couple days ago I switched over to just testing with Rspec for the plugin. It was so much faster and with setting up autospec for the plugin it was very nice to see my tests run every time I saved any file in the plugin directory. I don't know what I was thinking when I was trying to manually test my plugin. – Sean McCleary Oct 30 '09 at 18:02