Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Reload Rails code in development mode only when change is deteced
Ruby JavaScript
Tag: v0.2.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
Gemfile
README.md
Rakefile
active_reload.gemspec

README.md

Active Reload

The only Rails boost tool that doesn't try to be too smart.

Donate Active Reload at www.pledgie.com

Active Reload is a gem that changes a little when Rails code reloading is executed. Normally Rails "forgets" your code after every request in development mode and loads again necessary files during the request. If your application is big this can take lot of time especially on "dashboard" page that uses lot of different classes.

However this constant reloading is not always necessary. This gem changes it so it occurs before request and only when file was changed or added. It won't make reloading your app faster but it will skip reloading when nothing changed and that saved second can really sum up to a big value. It means that after change first request in development mode will reload the code and take as much time as it takes without this gem but subsequent request will be faster until next changes due to lack of code reloading.

Y U NO BELIEVE ?

Watch these videos for comparison:

2 simultaneous movies:

http://youtubedoubler.com/1fts

Spree in development mode without Active Reload

Spree in development mode

Spree in development and Active Reload enabled

Spree in development mode with enabled Active Reload

Installation

Simply add Active Reload to your Gemfile and bundle it up:

  gem 'active_reload'

Compatibility

It was hand tested only with Rails 3.0.9 but should work without any problem on any 3.0.* and 3.1.* Rails version. I'm in the middle of writing automatic tests for it.

It should work with any ruby compatible with 1.9.2 (ex. JRuby). Expect 1.8.7 support soon.

Notifications

You can subscribe to two notifications provided by this gem.

active_reload.set_clear_dependencies_hook_replaced event is triggered when the gem changes original rails hook for code reloading.

ActiveSupport::Notifications.subscribe("active_reload.set_clear_dependencies_hook_replaced") do |*args|
  event = ActiveSupport::Notifications::Event.new(*args)
  msg = event.name
  # Ubuntu: https://github.com/splattael/libnotify, Example: Libnotify.show(:body => msg, :summary => Rails.application.class.name, :timeout => 2.5, :append => true)
  # Macos: http://segment7.net/projects/ruby/growl/
  puts Rails.logger.warn(" --- #{msg} --- ")
end

active_support.dependencies.clear event is triggered when code reloading is triggered by this gem.

ActiveSupport::Notifications.subscribe("active_support.dependencies.clear") do |*args|
  msg = "Code reloaded!"
  # Ubuntu: https://github.com/splattael/libnotify, Example: Libnotify.show(:body => msg, :summary => Rails.application.class.name, :timeout => 2.5, :append => true)
  # Macos: http://segment7.net/projects/ruby/growl/
  puts Rails.logger.info(" --- #{msg} --- ")
end

Links

Do you want to reproduce the video experiment ?

The tested spree version was: https://github.com/spree/spree/tree/42795d91d3680394ef70126e6660cac3da81e8a9

It was installed in sandbox mode:

  git clone git://github.com/spree/spree.git spree
  cd spree
  git checkout 42795d91d3680394ef70126e6660cac3da81e8a9
  bundle install
  rake sandbox
  cd sandbox
  # Edit Gemfile to add or remove active_reload support
  rails server

Here is the ruby script that walks through the site using capybara:

require 'bbq/test' # https://github.com/drugpl/bbq
require 'benchmark'

shop = ["Ruby on Rails", "Apache", "Clothing", "Bags", "Mugs"]
admin = [
"Overview", 
"Orders", 
"Next", 
"Products", 
"Option Types", 
"Properties", 
"Prototypes", 
"Product Groups", 
"Reports", 
"Sales Total", 
"Configuration", 
"General Settings",
"Mail Methods",
"Tax Categories",
"Zones",
"States",
"Payment Methods",
"Taxonomies",
"Shipping Methods",
"Inventory Settings",
"Analytics Trackers",
"Complete List",
"Users",
"Promotions"
]

user = Bbq::TestUser.new(:driver => :selenium, :session => :default)
user.visit("/")

Benchmark.measure do

  shop.each do |link|
    user.click_on(link)
  end

  user.visit("/admin")
  user.fill_in("Email", :with => "spree@example.com")
  user.fill_in("Password", :with => "spree@example.com")
  user.click_button("Log In")

  admin.each do |link|
    user.click_on(link)
  end

  FileUtils.touch( Rails.root.join("app/controllers/application_controller.rb") )

  admin.first(5).each do |link|
    user.click_on(link)
  end

  user.click_on "Logout"

end
Something went wrong with that request. Please try again.