guard-rails 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,6 +1,9 @@
1
- *.gem
2
- .bundle
1
+ .rvmrc
2
+ .rspec
3
3
  Gemfile.lock
4
+
5
+ *.gem
6
+
7
+ .bundle/
4
8
  pkg/*
5
- .rvmrc
6
- tmp/
9
+ tmp/
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
- - ree
5
4
  - 2.0.0
5
+ - ree
6
+ - jruby
6
7
  script: "bundle exec rake spec"
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
+ # source 'http://ruby.taobao.org'
2
3
 
3
4
  # Specify your gem's dependencies in guard-rails.gemspec
4
5
  gemspec
data/README.md CHANGED
@@ -5,12 +5,29 @@
5
5
  [![Dependency Status](https://gemnasium.com/ranmocy/guard-rails.png)](https://gemnasium.com/ranmocy/guard-rails)
6
6
  [![Code Climate](https://codeclimate.com/github/ranmocy/guard-rails.png)](https://codeclimate.com/github/ranmocy/guard-rails)
7
7
 
8
- ## Want to restart your Rails development server whilst you work? Now you can!
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
- guard 'rails', :port => 5000 do
11
- watch('Gemfile.lock')
12
- watch(%r{^(config|lib)/.*})
13
- end
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
- Or
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
- Tell.me in: any.way
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
@@ -8,7 +8,7 @@ require 'rake/version_task'
8
8
  Rake::VersionTask.new
9
9
 
10
10
  include Rake::DSL if defined?(Rake::DSL)
11
- RVM_PREFIX = "rvm 1.8.7@guard-rails,1.9.3-p327@guard-rails,2.0.0@guard-rails do"
11
+ RVM_PREFIX = "rvm 1.8.7,1.9.3-p327,2.0.0 do"
12
12
 
13
13
 
14
14
  namespace :spec do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.4.0
@@ -33,15 +33,14 @@ module Guard
33
33
  end
34
34
 
35
35
  def start
36
- server = options[:server] ? "#{options[:server]} and " : ""
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
- action_cap = action.capitalize
43
- UI.info "#{action_cap}ing Rails..."
44
- Notifier.notify("Rails #{action}ing on port #{options[:port]} in #{options[:environment]} environment...", :title => "#{action_cap}ing Rails...", :image => :pending)
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)
@@ -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 %{kill -SIGINT #{pid}}
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 %{kill -KILL #{pid} >&2 2>/dev/null}
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 build_rails_command
38
- return %{#{options[:CLI]} --pid #{pid_file}} if options[:CLI]
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
- zeus_options = [
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 pid_file
61
- File.expand_path(options[:pid_file] || "tmp/pids/#{options[:environment]}.pid")
72
+ def build_cli_command
73
+ "#{options[:CLI]} --pid #{pid_file}"
62
74
  end
63
75
 
64
- def pid
65
- File.file?(pid_file) ? File.read(pid_file).to_i : nil
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 sleep_time
69
- options[:timeout].to_f / MAX_WAIT_COUNT.to_f
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
- Process.spawn @env, build_rails_command
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 %{kill -KILL #{pid}}
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
- %x{lsof -n -i TCP:#{options[:port]}}.each_line { |line|
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 '#build_rails_command' do
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.build_rails_command.should match(%r{#{custom_cli} --pid })
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.build_rails_command.should match(%r{#{custom_cli} --pid #{pid_file_path}})
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.build_rails_command.should_not match(%r{ -d})
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.build_rails_command.should match(%r{ -d})
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.build_rails_command.should match(%r{ -e development})
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.build_rails_command.should match(%r{ -e test})
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.build_rails_command.should match(%r{ -u})
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.build_rails_command.should match(%r{thin})
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.build_rails_command.should match(%r{ --pid #{pid_file_path}})
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.build_rails_command.should match(%r{ --pid #{pid_file_path}})
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.build_rails_command.should match(%r{zeus server })
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.build_rails_command.should match(%r{zeus test_server})
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.build_rails_command.should match(%r{zeus test_server .* thin})
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.build_rails_command.should_not match(%r{zeus server })
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.build_rails_command.should_not match(%r{test_server})
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.3.4
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-02-26 00:00:00.000000000 Z
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
- hash: -1932031982324360863
117
- required_rubygems_version: !ruby/object:Gem::Requirement
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
- hash: -1932031982324360863
123
+ version: '0'
124
+ hash: -3396796811439526258
125
+ none: false
126
126
  requirements: []
127
127
  rubyforge_project: guard-rails
128
- rubygems_version: 1.8.23
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.