Skip to content

Instantly share code, notes, and snippets.

@alloy
Forked from stepheneb/.kick
Created November 6, 2009 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alloy/227888 to your computer and use it in GitHub Desktop.
Save alloy/227888 to your computer and use it in GitHub Desktop.
# 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"
module Spork
def self.host
"druby://127.0.0.1:8989"
end
def self.start_server
DRb.start_service("druby://localhost:0")
DRbObject.new_with_uri(host)
end
def self.server
@server ||= start_server
end
def self.reload!
server.reload
rescue DRb::DRbConnError => e
if e.inspect =~ /connection closed/
# DRb::DRbConnError: connection closed
STDERR.puts e.inspect
log "spork server restarted ..."
else
# DRb::DRbConnError: druby://127.0.0.1:8989 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>
STDERR.puts e.inspect
log "spork server unreachable ..."
end
end
def self.call(files)
if files.any? { |f| f =~ /^(app|config|lib)/ }
reload!
# As a recipe this might not be a good idea, other recipes, or a local
# .kick script, might want to do stuff with these files.
files.clear
end
end
end
process Spork
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment