-
-
Save alloy/227888 to your computer and use it in GitHub Desktop.
This file contains 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
# 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