Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Created October 23, 2009 05:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stepheneb/216680 to your computer and use it in GitHub Desktop.
Save stepheneb/216680 to your computer and use it in GitHub Desktop.
A .kick file for use with the kicker gem to tell spork to reload rails
# Uses the kicker gem, a file-change watcher, using OS X FSEvents:
#
# http://github.com/alloy/kicker
# gem install kicker -s http://gemcutter.org
#
# to send a reload command via Drb to a running spork_server:
#
# http://github.com/timcharper/spork/
# gem install spork
#
# which should cause spork to reload rails.
#
# * Note the changes to spork to support reload are
# * currently only in the reload branch in my fork of
# * spork: http://github.com/stepheneb/spork
#
# Start the two server processes in console windows:
#
# spork rspec
# kicker
#
# When you make a change to a file in app/, lib/, or config/ this .kick
# script will send a reload message to spork to reload rails.
require "drb/drb"
process do |files|
if files.any? { |f| f =~ /^(app|config|lib)/ }
# A file has changed that could change the way the application
# operates ... tell spork to reload rails.
begin
DRb.start_service("druby://localhost:0")
spec_server = DRbObject.new_with_uri("druby://127.0.0.1:8989")
spec_server.reload
rescue DRb::DRbConnError => e
if e.inspect =~ /connection closed/
# DRb::DRbConnError: connection closed
STDERR.puts e.inspect
STDERR.puts "spork server restarted ..."
else
# DRb::DRbConnError: druby://127.0.0.1:8989 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
STDERR.puts e.inspect
STDERR.puts "spork server unreachable ..."
end
end
end
files.clear # Throw away all the changed file events ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment