Created
May 22, 2011 09:14
-
-
Save paneq/985294 to your computer and use it in GitHub Desktop.
Reload rails on demand instead of doing it after every request
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails.root/.gitignore | |
config/watchr.notify |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails.root/.watchr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# rails/railties/lib/rails/application/bootstrap.rb | |
initializer :set_clear_dependencies_hook do | |
unless config.cache_classes | |
changed_at = Proc.new{ File.new(File.join(Rails.root, '.watchr')).mtime } | |
last_change = changed_at.call | |
ActionDispatch::Callbacks.before do | |
change = changed_at.call | |
if change > last_change | |
Rails.logger.info("DETECTED CHANGES") | |
last_change = change | |
ActiveSupport::DescendantsTracker.clear | |
ActiveSupport::Dependencies.clear | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add to: | |
# Rails.root/config/environments/development.rb | |
# | |
# Faster code reloading: | |
if defined?(Rails::Server) # `rails s` only (not in `rails console`) | |
fork do | |
exec("watchr", "script/touch.watchr") | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails.root/Gemfile | |
# Bundle faster Rails instead: | |
gem 'rails', :git => 'git://github.com/paneq/rails.git', :branch => '3-0-7-faster' # https://github.com/paneq/rails/commit/9d1b49b1d409d8320dd537a407f42d7af27172fc | |
gem 'watchr' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rails.root/script/touch.watchr | |
require 'fileutils' | |
rails_root = File.expand_path('../..', __FILE__) | |
watchr_file = File.join(rails_root, '.watchr') | |
watch( 'app/(.*)\.rb' ) do |md| | |
FileUtils.touch(watchr_file) | |
begin | |
`test -f ./config/watchr.notify && notify-send -u low "Changed: #{md}"` # Notify on Ubuntu | |
rescue Errno::ENOENT | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment