guard-rails 0.3.4 → 0.4.0
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/.gitignore +7 -4
- data/.travis.yml +2 -1
- data/Gemfile +1 -0
- data/README.md +29 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/guard/rails.rb +4 -5
- data/lib/guard/rails/runner.rb +45 -25
- data/spec/lib/guard/rails/runner_spec.rb +39 -16
- metadata +21 -21
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,12 +5,29 @@
|
|
5
5
|
[](https://gemnasium.com/ranmocy/guard-rails)
|
6
6
|
[](https://codeclimate.com/github/ranmocy/guard-rails)
|
7
7
|
|
8
|
-
##
|
8
|
+
## Main repository
|
9
|
+
Currently, the official fork repository is at [ranmocy/guard-rails](http://github.com/ranmocy/guard-rails).
|
10
|
+
Please, come here and communicate with me.
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
## Install
|
13
|
+
|
14
|
+
Please make sure to have [Guard](https://github.com/guard/guard) installed before continue.
|
15
|
+
|
16
|
+
Add Guard::Rails to your `Gemfile`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
group :development do
|
20
|
+
gem 'guard-rails'
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
Add the default Guard::Rails template to your `Guardfile` by running:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ guard init rails
|
28
|
+
```
|
29
|
+
|
30
|
+
Now I can automatically restart your Rails development server as your files changed!
|
14
31
|
|
15
32
|
## Lots of fun options growing!
|
16
33
|
|
@@ -20,6 +37,7 @@
|
|
20
37
|
* `:force_run` kills any process that's holding the listen port before attempting to (re)start Rails (**default `false`**)
|
21
38
|
* `:pid_file` specify your pid\_file (**default `tmp/pids/[RAILS_ENV].pid`**)
|
22
39
|
* `:port` is the server port number (**default `3000`**)
|
40
|
+
* `:root` lets you specify the Rails root, i.e. for using guard-rails to run a dummy app within an engine (try `:root => '/spec/dummy'`).
|
23
41
|
* `:server` the webserver engine to use (**try `:server => :thin`**)
|
24
42
|
* `:start_on_start` will start the server when starting Guard (**default `true`**)
|
25
43
|
* `:timeout` waits when restarting the Rails server, in seconds (**default `30`**).
|
@@ -32,12 +50,15 @@
|
|
32
50
|
* **Multiple instances** use `pid_file` option to run multiple instances with same rails\_env
|
33
51
|
|
34
52
|
## Contribute
|
35
|
-
Feel free to fork'n'fix for any willing.
|
36
53
|
|
37
|
-
|
54
|
+
The best choise to contact me is the Issues and Pull Request system on GitHub.
|
55
|
+
Currently the official fork repository is at [ranmocy/guard-rails](http://github.com/ranmocy/guard-rails).
|
38
56
|
|
39
|
-
|
57
|
+
Please, post your issue or pull request there.
|
58
|
+
And I will be there as your call.
|
40
59
|
|
41
60
|
## Philosophy
|
42
61
|
|
62
|
+
* **All Platforms** MRI is the main test case. But will be tested under REE and JRuby.
|
63
|
+
* **Live in edge** I am tested under Ruby 1.8.7, 1.9.3, 2.0.0 with newest gems. Will be rewrited to fit Ruby 2.0.0 when I am released as version 1.0.0.
|
43
64
|
* [Semantic Version](http://semver.org/)
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/lib/guard/rails.rb
CHANGED
@@ -33,15 +33,14 @@ module Guard
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def start
|
36
|
-
|
37
|
-
UI.info "Guard::Rails will now restart your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
|
36
|
+
UI.info "[Guard::Rails] will restart #{options[:server]} on port #{options[:port]} in #{options[:environment]}."
|
38
37
|
reload("start") if options[:start_on_start]
|
39
38
|
end
|
40
39
|
|
41
40
|
def reload(action = "restart")
|
42
|
-
|
43
|
-
UI.info
|
44
|
-
Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]}
|
41
|
+
title = "#{action.capitalize}ing Rails..."
|
42
|
+
UI.info title
|
43
|
+
Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]}...", :title => title, :image => :pending)
|
45
44
|
if runner.restart
|
46
45
|
UI.info "Rails #{action}ed, pid #{runner.pid}"
|
47
46
|
Notifier.notify("Rails #{action}ed on port #{options[:port]}.", :title => "Rails #{action}ed!", :image => :success)
|
data/lib/guard/rails/runner.rb
CHANGED
@@ -7,8 +7,8 @@ module Guard
|
|
7
7
|
attr_reader :options
|
8
8
|
|
9
9
|
def initialize(options)
|
10
|
-
@env = ENV
|
11
10
|
@options = options
|
11
|
+
@root = options[:root] ? File.expand_path(options[:root]) : Dir.pwd
|
12
12
|
end
|
13
13
|
|
14
14
|
def start
|
@@ -20,11 +20,11 @@ module Guard
|
|
20
20
|
def stop
|
21
21
|
if File.file?(pid_file)
|
22
22
|
pid = File.read(pid_file).strip
|
23
|
-
system
|
23
|
+
system "kill -SIGINT #{pid}"
|
24
24
|
wait_for_no_pid if $?.exitstatus == 0
|
25
25
|
|
26
26
|
# If you lost your pid_file, you are already died.
|
27
|
-
system
|
27
|
+
system "kill -KILL #{pid} >&2 2>/dev/null"
|
28
28
|
FileUtils.rm pid_file, :force => true
|
29
29
|
end
|
30
30
|
end
|
@@ -34,9 +34,29 @@ module Guard
|
|
34
34
|
start
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
|
37
|
+
def build_command
|
38
|
+
command = build_cli_command if options[:CLI]
|
39
|
+
command ||= build_zeus_command if options[:zeus]
|
40
|
+
command ||= build_rails_command
|
41
|
+
"sh -c 'cd #{@root} && #{command} &'"
|
42
|
+
end
|
43
|
+
|
44
|
+
def pid_file
|
45
|
+
File.expand_path(options[:pid_file] || File.join(@root, "tmp/pids/#{options[:environment]}.pid"))
|
46
|
+
end
|
47
|
+
|
48
|
+
def pid
|
49
|
+
File.file?(pid_file) ? File.read(pid_file).to_i : nil
|
50
|
+
end
|
39
51
|
|
52
|
+
def sleep_time
|
53
|
+
options[:timeout].to_f / MAX_WAIT_COUNT.to_f
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# command builders
|
59
|
+
def build_options
|
40
60
|
rails_options = [
|
41
61
|
options[:daemon] ? '-d' : nil,
|
42
62
|
options[:debugger] ? '-u' : nil,
|
@@ -46,32 +66,31 @@ module Guard
|
|
46
66
|
options[:server],
|
47
67
|
]
|
48
68
|
|
49
|
-
|
50
|
-
options[:zeus_plan] || 'server',
|
51
|
-
]
|
52
|
-
|
53
|
-
# omit env when use zeus
|
54
|
-
@env['RAILS_ENV'] = options[:environment] if options[:environment] && options[:zeus].nil?
|
55
|
-
rails_runner = options[:zeus] ? "zeus #{zeus_options.join(' ')}" : "rails server"
|
56
|
-
|
57
|
-
%{#{rails_runner} #{rails_options.join(' ')}}
|
69
|
+
rails_options.join(' ')
|
58
70
|
end
|
59
71
|
|
60
|
-
def
|
61
|
-
|
72
|
+
def build_cli_command
|
73
|
+
"#{options[:CLI]} --pid #{pid_file}"
|
62
74
|
end
|
63
75
|
|
64
|
-
def
|
65
|
-
|
76
|
+
def build_zeus_command
|
77
|
+
zeus_options = [
|
78
|
+
options[:zeus_plan] || 'server',
|
79
|
+
]
|
80
|
+
|
81
|
+
# To avoid warning of Zeus
|
82
|
+
# Since setup RAILS_ENV is useless for Zeus
|
83
|
+
ENV['RAILS_ENV'] = nil
|
84
|
+
"zeus #{zeus_options.join(' ')} #{build_options}"
|
66
85
|
end
|
67
86
|
|
68
|
-
def
|
69
|
-
options[:
|
87
|
+
def build_rails_command
|
88
|
+
ENV['RAILS_ENV'] = options[:environment] if options[:environment]
|
89
|
+
"rails server #{build_options}"
|
70
90
|
end
|
71
91
|
|
72
|
-
private
|
73
92
|
def run_rails_command!
|
74
|
-
|
93
|
+
system build_command
|
75
94
|
end
|
76
95
|
|
77
96
|
def has_pid?
|
@@ -84,14 +103,15 @@ module Guard
|
|
84
103
|
|
85
104
|
def kill_unmanaged_pid!
|
86
105
|
if pid = unmanaged_pid
|
87
|
-
system
|
106
|
+
system "kill -KILL #{pid}"
|
88
107
|
FileUtils.rm pid_file
|
89
108
|
wait_for_no_pid
|
90
109
|
end
|
91
110
|
end
|
92
111
|
|
93
112
|
def unmanaged_pid
|
94
|
-
|
113
|
+
file_list = `lsof -n -i TCP:#{options[:port]}`
|
114
|
+
file_list.each_line { |line|
|
95
115
|
if line["*:#{options[:port]} "]
|
96
116
|
return line.split("\s")[1]
|
97
117
|
end
|
@@ -100,6 +120,7 @@ module Guard
|
|
100
120
|
end
|
101
121
|
|
102
122
|
private
|
123
|
+
|
103
124
|
def wait_for_pid
|
104
125
|
wait_for_pid_loop
|
105
126
|
end
|
@@ -118,4 +139,3 @@ module Guard
|
|
118
139
|
end
|
119
140
|
end
|
120
141
|
end
|
121
|
-
|
@@ -31,47 +31,62 @@ describe Guard::RailsRunner do
|
|
31
31
|
runner.pid.should be_nil
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
context 'custom rails root given' do
|
36
|
+
let(:options) { default_options.merge(:root => 'spec/dummy') }
|
37
|
+
let(:pid) { 12345 }
|
38
|
+
|
39
|
+
before do
|
40
|
+
FileUtils.mkdir_p File.split(runner.pid_file).first
|
41
|
+
File.open(runner.pid_file, 'w') { |fh| fh.print pid }
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should point to the right pid file" do
|
45
|
+
runner.pid_file.should match %r{spec/dummy/tmp/pids/development.pid}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
34
49
|
end
|
35
50
|
|
36
|
-
describe '#
|
51
|
+
describe '#build_command' do
|
37
52
|
context "CLI" do
|
38
53
|
let(:custom_cli) { 'custom_CLI_command' }
|
39
54
|
let(:options) { default_options.merge(:CLI => custom_cli) }
|
40
55
|
it "should have only custom CLI" do
|
41
|
-
runner.
|
56
|
+
runner.build_command.should match(%r{#{custom_cli} --pid })
|
42
57
|
end
|
43
58
|
|
44
59
|
let(:custom_pid_file) { "tmp/pids/rails_dev.pid" }
|
45
60
|
let(:options) { default_options.merge(:CLI => custom_cli, :pid_file => custom_pid_file) }
|
46
61
|
it "should use custom pid_file" do
|
47
62
|
pid_file_path = File.expand_path custom_pid_file
|
48
|
-
runner.
|
63
|
+
runner.build_command.should match(%r{#{custom_cli} --pid #{pid_file_path}})
|
49
64
|
end
|
50
65
|
end
|
51
66
|
|
52
67
|
context "daemon" do
|
53
68
|
it "should should not have daemon switch" do
|
54
|
-
runner.
|
69
|
+
runner.build_command.should_not match(%r{ -d})
|
55
70
|
end
|
56
71
|
end
|
57
72
|
|
58
73
|
context "no daemon" do
|
59
74
|
let(:options) { default_options.merge(:daemon => true) }
|
60
75
|
it "should have a daemon switch" do
|
61
|
-
runner.
|
76
|
+
runner.build_command.should match(%r{ -d})
|
62
77
|
end
|
63
78
|
end
|
64
79
|
|
65
80
|
context "development" do
|
66
81
|
it "should have environment switch to development" do
|
67
|
-
runner.
|
82
|
+
runner.build_command.should match(%r{ -e development})
|
68
83
|
end
|
69
84
|
end
|
70
85
|
|
71
86
|
context "test" do
|
72
87
|
let(:options) { default_options.merge(:environment => 'test') }
|
73
88
|
it "should have environment switch to test" do
|
74
|
-
runner.
|
89
|
+
runner.build_command.should match(%r{ -e test})
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
@@ -79,7 +94,7 @@ describe Guard::RailsRunner do
|
|
79
94
|
let(:options) { default_options.merge(:debugger => true) }
|
80
95
|
|
81
96
|
it "should have a debugger switch" do
|
82
|
-
runner.
|
97
|
+
runner.build_command.should match(%r{ -u})
|
83
98
|
end
|
84
99
|
end
|
85
100
|
|
@@ -87,14 +102,14 @@ describe Guard::RailsRunner do
|
|
87
102
|
let(:options) { default_options.merge(:server => 'thin') }
|
88
103
|
|
89
104
|
it "should have the server name" do
|
90
|
-
runner.
|
105
|
+
runner.build_command.should match(%r{thin})
|
91
106
|
end
|
92
107
|
end
|
93
108
|
|
94
109
|
context "no pid_file" do
|
95
110
|
it "should use default pid_file" do
|
96
111
|
pid_file_path = File.expand_path "tmp/pids/development.pid"
|
97
|
-
runner.
|
112
|
+
runner.build_command.should match(%r{ --pid #{pid_file_path}})
|
98
113
|
end
|
99
114
|
end
|
100
115
|
|
@@ -104,26 +119,26 @@ describe Guard::RailsRunner do
|
|
104
119
|
|
105
120
|
it "should use custom pid_file" do
|
106
121
|
pid_file_path = File.expand_path custom_pid_file
|
107
|
-
runner.
|
122
|
+
runner.build_command.should match(%r{ --pid #{pid_file_path}})
|
108
123
|
end
|
109
124
|
end
|
110
125
|
|
111
126
|
context "zeus enabled" do
|
112
127
|
let(:options) { default_options.merge(:zeus => true) }
|
113
128
|
it "should have zeus in command" do
|
114
|
-
runner.
|
129
|
+
runner.build_command.should match(%r{zeus server })
|
115
130
|
end
|
116
131
|
|
117
132
|
context "custom zeus plan" do
|
118
133
|
let(:options) { default_options.merge(:zeus => true, :zeus_plan => 'test_server') }
|
119
134
|
it "should use custom zeus plan" do
|
120
|
-
runner.
|
135
|
+
runner.build_command.should match(%r{zeus test_server})
|
121
136
|
end
|
122
137
|
|
123
138
|
context "custom server" do
|
124
139
|
let(:options) { default_options.merge(:zeus => true, :zeus_plan => 'test_server', :server => 'thin') }
|
125
140
|
it "should use custom server" do
|
126
|
-
runner.
|
141
|
+
runner.build_command.should match(%r{zeus test_server .* thin})
|
127
142
|
end
|
128
143
|
end
|
129
144
|
end
|
@@ -131,12 +146,20 @@ describe Guard::RailsRunner do
|
|
131
146
|
|
132
147
|
context "zeus disabled" do
|
133
148
|
it "should not have zeus in command" do
|
134
|
-
runner.
|
149
|
+
runner.build_command.should_not match(%r{zeus server })
|
135
150
|
end
|
136
151
|
|
137
152
|
let(:options) { default_options.merge(:zeus_plan => 'test_server') }
|
138
153
|
it "should have no effect of command" do
|
139
|
-
runner.
|
154
|
+
runner.build_command.should_not match(%r{test_server})
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'custom rails root' do
|
159
|
+
let(:options) { default_options.merge(:root => 'spec/dummy') }
|
160
|
+
|
161
|
+
it "should have a cd with the custom rails root" do
|
162
|
+
runner.build_command.should match(%r{cd .*/spec/dummy &&})
|
140
163
|
end
|
141
164
|
end
|
142
165
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,72 +10,72 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-
|
13
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
|
+
prerelease: false
|
16
17
|
name: guard
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 0.2.2
|
23
|
+
none: false
|
23
24
|
type: :runtime
|
24
|
-
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
26
|
requirements:
|
28
27
|
- - ! '>='
|
29
28
|
- !ruby/object:Gem::Version
|
30
29
|
version: 0.2.2
|
30
|
+
none: false
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
+
prerelease: false
|
32
33
|
name: rspec
|
33
34
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
35
|
requirements:
|
36
36
|
- - ! '>='
|
37
37
|
- !ruby/object:Gem::Version
|
38
38
|
version: 2.6.0
|
39
|
+
none: false
|
39
40
|
type: :development
|
40
|
-
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
42
|
requirements:
|
44
43
|
- - ! '>='
|
45
44
|
- !ruby/object:Gem::Version
|
46
45
|
version: 2.6.0
|
46
|
+
none: false
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
+
prerelease: false
|
48
49
|
name: mocha
|
49
50
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.13.1
|
55
|
+
none: false
|
55
56
|
type: :development
|
56
|
-
prerelease: false
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
58
|
requirements:
|
60
59
|
- - ! '>='
|
61
60
|
- !ruby/object:Gem::Version
|
62
61
|
version: 0.13.1
|
62
|
+
none: false
|
63
63
|
- !ruby/object:Gem::Dependency
|
64
|
+
prerelease: false
|
64
65
|
name: version
|
65
66
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
67
|
requirements:
|
68
68
|
- - ! '>='
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: 1.0.0
|
71
|
+
none: false
|
71
72
|
type: :development
|
72
|
-
prerelease: false
|
73
73
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
74
|
requirements:
|
76
75
|
- - ! '>='
|
77
76
|
- !ruby/object:Gem::Version
|
78
77
|
version: 1.0.0
|
78
|
+
none: false
|
79
79
|
description: Restart Rails when things change in your app
|
80
80
|
email:
|
81
81
|
- john@coswellproductions.com
|
@@ -106,26 +106,26 @@ rdoc_options: []
|
|
106
106
|
require_paths:
|
107
107
|
- lib
|
108
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
-
none: false
|
110
109
|
requirements:
|
111
110
|
- - ! '>='
|
112
111
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0'
|
114
112
|
segments:
|
115
113
|
- 0
|
116
|
-
|
117
|
-
|
114
|
+
version: '0'
|
115
|
+
hash: -3396796811439526258
|
118
116
|
none: false
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
118
|
requirements:
|
120
119
|
- - ! '>='
|
121
120
|
- !ruby/object:Gem::Version
|
122
|
-
version: '0'
|
123
121
|
segments:
|
124
122
|
- 0
|
125
|
-
|
123
|
+
version: '0'
|
124
|
+
hash: -3396796811439526258
|
125
|
+
none: false
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project: guard-rails
|
128
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.25
|
129
129
|
signing_key:
|
130
130
|
specification_version: 3
|
131
131
|
summary: Guard your Rails to always be there.
|