alexch-rerun 0.2.1 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,14 +5,22 @@
5
5
  Launches your app, then watches the filesystem. If a relevant file
6
6
  changes, then it restarts your app.
7
7
 
8
- Currently only *.rb files are watched, anywhere under the current
9
- directory (.). This is pretty lame so it will change soon.
8
+ Currently only *.rb files are watched. This is pretty lame so it will
9
+ change soon.
10
10
 
11
11
  If you're on Mac OS X, it uses the built-in facilities for monitoring
12
- the filesystem, so CPU use is very light.
12
+ the filesystem, so CPU use is very light. And if you have "growlnotify"
13
+ available on the PATH, it sends notifications to growl in addition to
14
+ the console. Here's how to install
15
+ [growlnotify](http://growl.info/documentation/growlnotify.php):
13
16
 
14
- If you have "growlcmd" available on the PATH, it sends notifications
15
- to growl in addition to the console.
17
+ > In your shell, cd to the directory on the Growl disk image
18
+ > containing growlnotify, and type ./install.sh. That script
19
+ > will install growlnotify to /usr/local/bin and the manpage
20
+ > to /usr/local/man.
21
+
22
+ Rerun does not work on Windows. Sorry, but you can't do much relaunching
23
+ without "fork".
16
24
 
17
25
  # Installation:
18
26
 
@@ -42,14 +50,18 @@ but you want it on port 4000 and in debug mode:
42
50
 
43
51
  # Options:
44
52
 
45
- Only --version and --help so far.
53
+ --dir directory to watch (default = ".")
54
+
55
+ Also --version and --help.
46
56
 
47
57
  # To Do:
48
58
 
49
59
  * If the cmd is, or starts with, a ".rb" file, then run it with ruby
60
+ * Watch arbitrary file types via globbing
50
61
  * Allow arbitrary sets of directories and file types, possibly with "include" and "exclude" sets
51
62
  * ".rerun" file to specify options per project or in $HOME.
52
- * Test on Windows and Linux.
63
+ * Test on Linux.
64
+ * Test on Mac without Growlnotify.
53
65
 
54
66
  # Other projects that do similar things
55
67
 
@@ -59,6 +71,8 @@ Shotgun: <http://github.com/rtomayko/shotgun>
59
71
 
60
72
  Rack::Reloader middleware: <http://github.com/rack/rack/blob/5ca8f82fb59f0bf0e8fd438e8e91c5acf3d98e44/lib/rack/reloader.rb>
61
73
 
74
+ and the Sinatra FAQ has a discussion at <http://www.sinatrarb.com/faq.html#reloading>
75
+
62
76
  # Why would I use this instead of Shotgun?
63
77
 
64
78
  Shotgun does a "fork" after the web framework has loaded but before
@@ -81,6 +95,20 @@ server so this doesn't affect them too much.
81
95
 
82
96
  YMMV!
83
97
 
98
+ # Why would I use this instead of Rack::Reloader?
99
+
100
+ Rack::Reloader is certifiably beautiful code, and is a very elegant use
101
+ of Rack's middleware architecture. But because it relies on the
102
+ LOADED_FEATURES variable, it only reloads .rb files that were 'require'd,
103
+ not 'load'ed. That leaves out (non-Erector) template files, and also,
104
+ the way I was doing it, sub-actions (see
105
+ [this thread](http://groups.google.com/group/sinatrarb/browse_thread/thread/7329727a9296e96a#
106
+ )).
107
+
108
+ Rack::Reloader also doesn't reload configuration changes or redo other
109
+ things that happen during app startup. Rerun takes the attitude that if
110
+ you want to restart an app, you should just restart the whole app. You know?
111
+
84
112
  # Why did you write this?
85
113
 
86
114
  I've been using [Sinatra](http://sinatrarb.com) and loving it. In order
@@ -101,6 +129,7 @@ Based upon and/or inspired by:
101
129
  Shotgun: <http://github.com/rtomayko/shotgun>
102
130
 
103
131
  Rspactor: <http://github.com/mislav/rspactor>
132
+ (In turn based on http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/ )
104
133
 
105
134
  FileSystemWatcher: <http://paulhorman.com/filesystemwatcher/>
106
135
 
data/bin/rerun CHANGED
@@ -20,6 +20,10 @@ opts = OptionParser.new("", 24, ' ') { |opts|
20
20
  opts.separator ""
21
21
  opts.separator "Options:"
22
22
 
23
+ opts.on("-d dir", "--dir dir", "directory to watch") do |dir|
24
+ options[:dir] = dir
25
+ end
26
+
23
27
  opts.on_tail("-h", "--help", "--usage", "show this message") do
24
28
  puts opts
25
29
  exit
@@ -1,16 +1,6 @@
1
1
  require "system"
2
2
  require "watcher"
3
3
 
4
- begin
5
- require 'osx/foundation'
6
- OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
7
- rescue MissingSourceFile
8
- # this is to not fail when running on a non-Mac
9
- end
10
-
11
- # stolen from RSpactor, http://github.com/mislav/rspactor
12
- # based on http://rails.aizatto.com/2007/11/28/taming-the-autotest-beast-with-fsevents/
13
-
14
4
  #TODO: make it notice deleted files
15
5
  require "watcher"
16
6
  module Rerun
@@ -3,7 +3,7 @@ require "watcher"
3
3
  require "osxwatcher"
4
4
  require "fswatcher"
5
5
 
6
- # todo: make this work in non-Mac and non-Unix environments (also Macs without growlnotify)
6
+ # todo: make sure this works in non-Mac environments (also Macs without growlnotify)
7
7
  module Rerun
8
8
  class Runner
9
9
 
@@ -20,7 +20,15 @@ module Rerun
20
20
  @restarting = false
21
21
  end
22
22
 
23
+ def dir
24
+ @options[:dir] || "."
25
+ end
26
+
23
27
  def start
28
+ if windows?
29
+ raise "Sorry, Rerun does not work on Windows."
30
+ end
31
+
24
32
  if (!@already_running)
25
33
  taglines = [
26
34
  "To infinity... and beyond!",
@@ -37,13 +45,20 @@ module Rerun
37
45
  end
38
46
 
39
47
  @pid = Kernel.fork do
40
- # Signal.trap("INT") { exit }
41
- exec(@run_command)
48
+ begin
49
+ # Signal.trap("INT") { exit }
50
+ exec(@run_command)
51
+ rescue => e
52
+ puts e
53
+ exit
54
+ end
42
55
  end
56
+ Process.detach(@pid) # so if the child exits, it dies
43
57
 
44
- Signal.trap("INT") { stop; exit }
45
-
46
- # Process.detach(@pid)
58
+ Signal.trap("INT") do # INT = control-C
59
+ stop # first stop the child
60
+ exit
61
+ end
47
62
 
48
63
  begin
49
64
  sleep 2
@@ -59,16 +74,16 @@ module Rerun
59
74
  end
60
75
 
61
76
  unless @watcher
62
- watcher_class = osx? ? OSXWatcher : FSWatcher
77
+ watcher_class = mac? ? OSXWatcher : FSWatcher
63
78
  # watcher_class = FSWatcher
64
79
 
65
80
  watcher = watcher_class.new do
66
81
  restart unless @restarting
67
82
  end
68
- watcher.add_directory(".", "**/*.rb")
83
+ puts "Watching #{dir}"
84
+ watcher.add_directory(dir, "**/*.rb")
69
85
  watcher.sleep_time = 1
70
86
  watcher.start
71
-
72
87
  @watcher = watcher
73
88
  end
74
89
 
@@ -110,7 +125,7 @@ module Rerun
110
125
  end
111
126
 
112
127
  def notify(title, body)
113
- growl title, body if has_growl?
128
+ growl title, body
114
129
  puts
115
130
  puts "#{Time.now.strftime("%T")} - #{app_name} #{title}"
116
131
  end
@@ -1,22 +1,30 @@
1
+ def mac?
2
+ RUBY_PLATFORM =~ /darwin/i && !$osx_foundation_failed_to_load
3
+ end
4
+
5
+ def windows?
6
+ RUBY_PLATFORM =~ /mswin/i
7
+ end
1
8
 
2
- # are we on OSX or not?
3
- begin
4
- require 'osx/foundation'
5
- OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
6
- $osx = true
7
- rescue MissingSourceFile
8
- # this is to not fail when running on a non-Mac
9
+ def linux?
10
+ RUBY_PLATFORM =~ /linux/i
11
+ end
12
+
13
+ if mac?
14
+ begin
15
+ require 'osx/foundation'
16
+ OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
17
+ rescue
18
+ $osx_foundation_failed_to_load = true
19
+ end
9
20
  end
10
21
 
11
22
  module Rerun
12
23
  module System
13
- def osx?
14
- $osx
15
- end
16
-
24
+
17
25
  # do we have growl or not?
18
- def has_growl?
19
- growlcmd != ""
26
+ def growl?
27
+ mac? && (growlcmd != "")
20
28
  end
21
29
 
22
30
  def growlcmd
@@ -29,9 +37,11 @@ module Rerun
29
37
  end
30
38
 
31
39
  def growl(title, body, background = true)
32
- s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\""
33
- s += " &" if background
34
- `#{s}`
40
+ if growl?
41
+ s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\""
42
+ s += " &" if background
43
+ `#{s}`
44
+ end
35
45
  end
36
46
 
37
47
  end
@@ -3,7 +3,7 @@ $spec = Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'rerun'
6
- s.version = '0.2.1'
6
+ s.version = '0.3'
7
7
  s.date = '2009-06-16'
8
8
 
9
9
  s.description = "Restarts your app when a file changes"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexch-rerun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: "0.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee