• Stars
    star
    371
  • Rank 115,103 (Top 3 %)
  • Language
    Ruby
  • License
    Other
  • Created over 13 years ago
  • Updated almost 13 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reload Rails code in development mode only when change is deteced

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.

News

Rails 3.2

This gem is incompatbile with Rails 3.2 and needs to be removed from the Gemfile when upgrading. This has no drawbacks, because it has been incorporated into Rails 3.2 which was my plan since the first release. Also during that process Jose Valim fixed some bugs and added few useful features that it was missing. In other words, probably the easiest way to use it and have the best experience is to upgrade your Rails app.

Not supported anymore

Because of that and having in mind that it works fine for most Rails 3.0 and 3.1 applications I decided to no longer support it. It provided value to lot of people, make them happier and more productive so this is now a community responsibility to take care of this feature in Rails code.

It works for you so you want to thank? There are many options:

  • Meet me at wroc_love.rb conference : http://wrocloverb.com/ and buy me a beer.
  • Tweet about the gem
  • Tell you friends to try it
  • Donate

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 in development group and bundle it up:

  group :development do
    gem 'active_reload'
  end
  bundle install

Compatibility

Tested with Ruby 1.9.2 and 1.8.7. Tested with Rails 3.0.10 and 3.1.0.rc6 (older versions of this gem have been tested with older rails versions, check it by reading README.md in older tag versions)

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

Testing & Contribution

cd active_reload

bundle install
cd test/dummy309/
bundle install
cd ../..

cd test/dummy310rc5/
bundle install
cd ../..

bundle exec rake test

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 => "[email protected]")
  user.fill_in("Password", :with => "[email protected]")
  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

More Repositories

1

activemodel-warnings

Mark some validations as optional and let them be skipped
Ruby
38
star
2

not_activerecord

not_activerecord
Ruby
15
star
3

manage-my-money

Personal accounting webapp written in Ruby on Rails
Ruby
11
star
4

web3-celluloid

Notifications with websockets using Celluloid::IO and em-websockets code for parsing the protocol
JavaScript
6
star
5

inbox

Displays emails sent to the users in action_mailer.delivery_method = :test mode
Ruby
5
star
6

as_readonly

Expose your collections as readonly objects without fear
Ruby
4
star
7

rails3-demos

Rails3 Demo application
Ruby
4
star
8

capybara-js_finders

Additional finder for capybara that for some reason cannot use only xpath for finding nodes but needs to execute js for some calculations
Ruby
3
star
9

celluloid-fun

Having fun with celluloid
Ruby
2
star
10

inventory

Thousand ways to play with the concept of Inventory. Like coderetreat but over longer period of time.
Ruby
2
star
11

ApotomoBug28Example

Helpers not reloading
Ruby
1
star
12

code_methods

Dynamically create methods for acessing AR objectes with one column value that equals to generated method name.
Ruby
1
star
13

uwr-eventmachine-talk

Ruby
1
star
14

minitest-instrument-db

Store information about speed of test execution provided by minitest-instrument
Ruby
1
star
15

minitest-instrument

Instrument ActiveSupport::Notifications when test method is executed
Ruby
1
star
16

i18n-lesson-learnt

i18n-lesson-learnt DRUG pres
1
star
17

rails3-active_model-filter-example

Rails3 example application with filtering based on ActiveModel
Ruby
1
star
18

global_boolean

Parse boolean strings like "true" or "1" without a problem
Ruby
1
star
19

web3-em

Notifications with websockets using EventMachine and Goliath
JavaScript
1
star
20

m2r_drug

Lightning talk about m2r for DRUG meeting
1
star
21

mongrel2_lightning_io

My lightning talk about mongrel2 for lightning.io conference (2012 Poznań)
1
star
22

drug_testing_external

Presentation about testing communication with external web services
1
star
23

drug_views_iq

Presentation about my thoughts about views in Rails
Ruby
1
star
24

bbq-widget

Widgets for bbq
Ruby
1
star
25

kotlink-kafka-tutorial

doing: Kafka tutorial #1 - Simple Kafka producer in Kotlin - https://aseigneurin.github.io/2018/08/01/kafka-tutorial-1-simple-producer-in-kotlin.html
Kotlin
1
star
26

active-model-errors-as-objects-example

This is a proof of concept application that ActiveModel errors can be objects.
Ruby
1
star
27

drug-activemodel-presentation

Presentation about Active model in Rails 3 for Drug
1
star
28

meme-middleware

Find meme references in your pages and convert them to images
Ruby
1
star