Welcome aboard
You’re riding Ruby on Rails!
Getting started
Here’s how to get rolling:
-
Use
rails generateto create your models and controllersTo see all available options, run it without parameters.
-
Set up a default route and remove or rename this file
Routes are set up in config/routes.rb.
-
Create your database
Run
rake db:migrateto create your database. If you're not using SQLite (the default), editconfig/database.ymlwith your username and password.
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 and Active Reload enabled
## Installation
Simply add Active Reload to your Gemfile in development group and bundle it up:
```ruby
group :development do
gem 'active_reload'
end
```
```bash
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.
```ruby
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.
```ruby
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
* http://blog.robert.pankowecki.pl/2011/06/faster-rails-development-part-2.html
* http://blog.robert.pankowecki.pl/2011/05/get-faster-rails-development.html
## Testing & Contribution
```bash
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:
```bash
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:
```ruby
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
```
================================================
FILE: Rakefile
================================================
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
Bundler::GemHelper.install_tasks
require 'rdoc/task'
RDoc::Task.new do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Bbq'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/unit/*_test.rb' # Don't load test/dummy/test
t.verbose = false
end
task :default => :test
================================================
FILE: active_reload.gemspec
================================================
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "active_reload/version"
Gem::Specification.new do |s|
s.name = "active_reload"
s.version = ActiveReload::VERSION
s.authors = ["Robert Pankowecki"]
s.email = ["robert.pankowecki@gmail.com"]
s.homepage = "https://github.com/paneq/active_reload"
s.summary = %q{Reload Rails code in development mode only when a change is detected}
s.description = %q{Reload Rails code in development mode only when a change is detected}
s.rubyforge_project = "active_reload"
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
s.add_development_dependency "rake"
s.add_development_dependency "active_support"
s.add_development_dependency "bbq"
end
================================================
FILE: lib/active_reload/version.rb
================================================
module ActiveReload
VERSION = "0.6.1"
end
================================================
FILE: lib/active_reload.rb
================================================
require "active_reload/version"
require 'rails/railtie'
require 'active_support/notifications'
require 'active_support/dependencies'
module ActiveReload
class Railtie < ::Rails::Railtie
initializer :'active_reload.set_clear_dependencies_hook', :after => :set_clear_dependencies_hook do
ActiveReload.replace!
end
end # Railtie
module ProcInspector
if RUBY_VERSION.start_with?("1.8")
# Proc#source_location is not available in Ruby 1.8
def source_file
# Extract from format like this: "#