rerun 0.2.1 → 0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- rerun
1
+ Rerun
2
2
  Copyright (c) 2009 Alex Chaffee <alex@stinky.com>
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -21,9 +21,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
  ---
22
22
 
23
23
  rerun partially based on code from Rspactor
24
- [insert license]
24
+ Copyright (c) 2009 Mislav Marohnić
25
+ License as above (MIT open source).
25
26
 
26
27
  rerun partially based on code from FileSystemWatcher
27
28
  http://paulhorman.com/filesystemwatcher/
28
- [insert license]
29
+ No license provided; assumed public domain.
30
+
31
+ rerun partially based on code from Shotgun
32
+ Copyright (c) 2009 Ryan Tomayko <tomayko.com/about>
33
+ License as above (MIT open source).
29
34
 
data/README.md CHANGED
@@ -5,25 +5,34 @@
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
 
19
27
  sudo gem install rerun
20
28
 
21
- or...
29
+ If you want to use the latest version, grab it off Github:
22
30
 
23
31
  gem sources -a http://gems.github.com/
24
32
  sudo gem install alexch-rerun
25
33
 
26
- (The github way isn't working yet for some reason. Maybe I have to wait for cron to run or something.)
34
+ I'll bump the version on Github for release candidates, and deploy to
35
+ Rubyforge only when it's had some time to bake.
27
36
 
28
37
  # Usage:
29
38
 
@@ -35,20 +44,24 @@ app.rb:
35
44
  rerun app.rb
36
45
 
37
46
  Or if you're running a Rack app that's configured in config.ru
38
- but you want to override its port:
47
+ but you want it on port 4000 and in debug mode:
39
48
 
40
- rerun "thin start --port=4000 -R config.ru"
41
-
49
+ rerun "thin start --debug --port=4000 -R config.ru"
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
 
59
+ * If the cmd is, or starts with, a ".rb" file, then run it with ruby
60
+ * Watch arbitrary file types via globbing
49
61
  * Allow arbitrary sets of directories and file types, possibly with "include" and "exclude" sets
50
62
  * ".rerun" file to specify options per project or in $HOME.
51
- * Test on Windows and Linux.
63
+ * Test on Linux.
64
+ * Test on Mac without Growlnotify.
52
65
 
53
66
  # Other projects that do similar things
54
67
 
@@ -56,6 +69,10 @@ Restartomatic: <http://github.com/adammck/restartomatic>
56
69
 
57
70
  Shotgun: <http://github.com/rtomayko/shotgun>
58
71
 
72
+ Rack::Reloader middleware: <http://github.com/rack/rack/blob/5ca8f82fb59f0bf0e8fd438e8e91c5acf3d98e44/lib/rack/reloader.rb>
73
+
74
+ and the Sinatra FAQ has a discussion at <http://www.sinatrarb.com/faq.html#reloading>
75
+
59
76
  # Why would I use this instead of Shotgun?
60
77
 
61
78
  Shotgun does a "fork" after the web framework has loaded but before
@@ -78,14 +95,30 @@ server so this doesn't affect them too much.
78
95
 
79
96
  YMMV!
80
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
+
81
112
  # Why did you write this?
82
113
 
83
- I've been using [Sinatra](http://sinatrarb.com) and loving it. In
84
- order to simplify their system, the Rat Pack just took out
85
- auto-reloading. I approve of this: a web application framework should
86
- be focused on serving requests, not on munging Ruby ObjectSpace. But
87
- I still wanted automatic reloading during development. Shotgun wasn't
88
- working for me (see above) so I spliced Rerun together out of .
114
+ I've been using [Sinatra](http://sinatrarb.com) and loving it. In order
115
+ to simplify their system, the Rat Pack just removed auto-reloading from
116
+ Sinatra proper. I approve of this: a web application framework should be
117
+ focused on serving requests, not on munging Ruby ObjectSpace for
118
+ dev-time convenience. But I still wanted automatic reloading during
119
+ development. Shotgun wasn't working for me (see above) so I spliced
120
+ Rerun together out of code from Rspactor, FileSystemWatcher, and Shotgun
121
+ -- with a heavy amount of refactoring and rewriting.
89
122
 
90
123
  # Credits
91
124
 
@@ -96,9 +129,14 @@ Based upon and/or inspired by:
96
129
  Shotgun: <http://github.com/rtomayko/shotgun>
97
130
 
98
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/ )
99
133
 
100
134
  FileSystemWatcher: <http://paulhorman.com/filesystemwatcher/>
101
135
 
136
+ Patches by:
137
+
138
+ David Billskog <billskog@gmail.com>
139
+
102
140
  # License
103
141
 
104
142
  Open Source MIT License. See "LICENSE" file.
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
data/lib/osxwatcher.rb CHANGED
@@ -1,17 +1,8 @@
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
- #TODO: make it notice deleted files
4
+ #TODO: make it notice deleted files natively, rather than passing to 'examine'
5
+ #TODO: use http://github.com/spicycode/fsevent
15
6
  require "watcher"
16
7
  module Rerun
17
8
  class OSXWatcher < Rerun::Watcher
data/lib/rerun.rb CHANGED
@@ -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
data/lib/system.rb CHANGED
@@ -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 LoadError
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
data/rerun.gemspec CHANGED
@@ -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.4'
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: rerun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: "0.4"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaffee
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements: []
57
57
 
58
58
  rubyforge_project: pivotalrb
59
- rubygems_version: 1.3.3
59
+ rubygems_version: 1.3.5
60
60
  signing_key:
61
61
  specification_version: 2
62
62
  summary: Launches an app, and restarts it whenever the filesystem changes.