guard-puma 0.4.0 → 0.4.1
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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +1 -0
- data/lib/guard/puma.rb +23 -7
- data/lib/guard/puma/version.rb +1 -1
- data/spec/lib/guard/puma_spec.rb +105 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba3c0c0435df8f3c4ebc9383ae9afbd92bd2f41d
|
4
|
+
data.tar.gz: c89ab9b1313f04b420a8ac8be2dc6a2b685f9440
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3bf2e82c1da9bdfc4ae1d78244455642b5a07f242f0af7f4998b121492214b5322d5094b9f21b538575d04d2599a93c813055d7a07e614e98f07bce176aa60a
|
7
|
+
data.tar.gz: 073f9b90a53e4aed7fd27c282d63b50ff82f54e57fec7d6579a5446d24dd539648630d0a66f99bc16f88f47ad61f27ec6c35c9a96f431bc676b00aaa8e2ec9f9
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -44,6 +44,7 @@ end
|
|
44
44
|
* `:control_token` is the token to use as authentication for the control server(optional)
|
45
45
|
* `:control_port` is the port to use for the control server(optional)
|
46
46
|
* `:threads` is the min:max number of threads to use. Defaults to 0:16 (optional)
|
47
|
+
* `:notifications` is the list of notification types that will be sent. Defaults to `[:restarting, :restarted, :not_restarted, :stopped]` (optional)
|
47
48
|
|
48
49
|
## Contributing
|
49
50
|
|
data/lib/guard/puma.rb
CHANGED
@@ -19,40 +19,56 @@ module Guard
|
|
19
19
|
:start_on_start => true,
|
20
20
|
:force_run => false,
|
21
21
|
:timeout => 20,
|
22
|
-
:debugger => false
|
22
|
+
:debugger => false,
|
23
|
+
:notifications => %i[restarting restarted not_restarted stopped]
|
23
24
|
}
|
24
25
|
|
25
26
|
def initialize(options = {})
|
26
27
|
super
|
27
28
|
@options = DEFAULT_OPTIONS.merge(options)
|
29
|
+
@options[:port] = nil if @options.key?(:config)
|
28
30
|
@runner = ::Guard::PumaRunner.new(@options)
|
29
31
|
end
|
30
32
|
|
31
33
|
def start
|
32
34
|
server = options[:server] ? "#{options[:server]} and " : ""
|
33
|
-
UI.info "
|
35
|
+
UI.info "Puma starting#{port_text} in #{server}#{options[:environment]} environment."
|
34
36
|
runner.start if options[:start_on_start]
|
35
37
|
end
|
36
38
|
|
37
39
|
def reload
|
38
40
|
UI.info "Restarting Puma..."
|
39
|
-
|
41
|
+
if options[:notifications].include?(:restarting)
|
42
|
+
Notifier.notify("Puma restarting#{port_text} in #{options[:environment]} environment...", :title => "Restarting Puma...", :image => :pending)
|
43
|
+
end
|
40
44
|
if runner.restart
|
41
45
|
UI.info "Puma restarted"
|
42
|
-
|
46
|
+
if options[:notifications].include?(:restarted)
|
47
|
+
Notifier.notify("Puma restarted#{port_text}.", :title => "Puma restarted!", :image => :success)
|
48
|
+
end
|
43
49
|
else
|
44
50
|
UI.info "Puma NOT restarted, check your log files."
|
45
|
-
|
51
|
+
if options[:notifications].include?(:not_restarted)
|
52
|
+
Notifier.notify("Puma NOT restarted, check your log files.", :title => "Puma NOT restarted!", :image => :failed)
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
49
57
|
def stop
|
50
|
-
|
58
|
+
if options[:notifications].include?(:stopped)
|
59
|
+
Notifier.notify("Until next time...", :title => "Puma shutting down.", :image => :pending)
|
60
|
+
end
|
51
61
|
runner.halt
|
52
62
|
end
|
53
63
|
|
54
|
-
def
|
64
|
+
def run_on_changes(paths)
|
55
65
|
reload
|
56
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def port_text
|
71
|
+
" on port #{options[:port]}" if options[:port]
|
72
|
+
end
|
57
73
|
end
|
58
74
|
end
|
data/lib/guard/puma/version.rb
CHANGED
data/spec/lib/guard/puma_spec.rb
CHANGED
@@ -12,6 +12,18 @@ describe Guard::Puma do
|
|
12
12
|
|
13
13
|
expect(guard.runner.options[:port]).to eq(4000)
|
14
14
|
end
|
15
|
+
|
16
|
+
context "when config is set" do
|
17
|
+
let(:options) { { :config => 'config.rb' } }
|
18
|
+
|
19
|
+
it "initializes with config option" do
|
20
|
+
expect(guard.runner.options[:config]).to eq('config.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "initializes without port option" do
|
24
|
+
expect(guard.runner.options[:port]).to be_nil
|
25
|
+
end
|
26
|
+
end
|
15
27
|
end
|
16
28
|
|
17
29
|
describe "#default_env" do
|
@@ -61,40 +73,121 @@ describe Guard::Puma do
|
|
61
73
|
guard.start
|
62
74
|
end
|
63
75
|
end
|
76
|
+
|
77
|
+
describe "UI message" do
|
78
|
+
before do
|
79
|
+
allow(guard.runner).to receive(:start)
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when no config option set" do
|
83
|
+
it "contains port" do
|
84
|
+
expect(Guard::UI).to receive(:info).with(/starting on port 4000/)
|
85
|
+
guard.start
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when config option set" do
|
90
|
+
let(:options) { { :config => 'config.rb' } }
|
91
|
+
|
92
|
+
it "doesn't contain port" do
|
93
|
+
expect(Guard::UI).to receive(:info).with(/starting/)
|
94
|
+
guard.start
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
64
98
|
end
|
65
99
|
|
66
100
|
describe '#reload' do
|
67
101
|
|
68
102
|
before do
|
69
103
|
expect(Guard::UI).to receive(:info).with('Restarting Puma...')
|
70
|
-
expect(Guard::
|
104
|
+
expect(Guard::UI).to receive(:info).with('Puma restarted')
|
71
105
|
allow(guard.runner).to receive(:restart).and_return(true)
|
72
106
|
end
|
73
107
|
|
74
108
|
let(:runner_stub) { allow_any_instance_of(Guard::PumaRunner).to receive(:halt) }
|
75
109
|
|
76
|
-
|
77
|
-
|
78
|
-
|
110
|
+
context "with default options" do
|
111
|
+
it "restarts and show the message" do
|
112
|
+
expect(Guard::Notifier).to receive(:notify).with(
|
113
|
+
/restarting on port 4000/,
|
114
|
+
hash_including(:title => "Restarting Puma...", :image => :pending)
|
115
|
+
)
|
79
116
|
|
80
|
-
|
117
|
+
expect(Guard::Notifier).to receive(:notify).with(
|
118
|
+
"Puma restarted on port 4000.",
|
119
|
+
hash_including(:title => "Puma restarted!", :image => :success)
|
120
|
+
)
|
121
|
+
|
122
|
+
guard.reload
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "with config option set" do
|
127
|
+
let(:options) { { :config => "config.rb" } }
|
128
|
+
|
129
|
+
it "restarts and show the message" do
|
130
|
+
expect(Guard::Notifier).to receive(:notify).with(
|
131
|
+
/restarting/,
|
132
|
+
hash_including(:title => "Restarting Puma...", :image => :pending)
|
133
|
+
)
|
134
|
+
|
135
|
+
expect(Guard::Notifier).to receive(:notify).with(
|
136
|
+
"Puma restarted.",
|
137
|
+
hash_including(:title => "Puma restarted!", :image => :success)
|
138
|
+
)
|
139
|
+
|
140
|
+
guard.reload
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context "with custom :notifications option" do
|
145
|
+
let(:options) { { :notifications => [:restarted] } }
|
146
|
+
|
147
|
+
it "restarts and show the message only about restarted" do
|
148
|
+
expect(Guard::Notifier).not_to receive(:notify).with(/restarting/)
|
149
|
+
expect(Guard::Notifier).to receive(:notify).with(/restarted/, kind_of(Hash))
|
150
|
+
|
151
|
+
guard.reload
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "with empty :notifications option" do
|
156
|
+
let(:options) { { :notifications => [] } }
|
157
|
+
|
158
|
+
it "restarts and doesn't show the message" do
|
159
|
+
expect(Guard::Notifier).not_to receive(:notify)
|
160
|
+
|
161
|
+
guard.reload
|
162
|
+
end
|
81
163
|
end
|
82
164
|
|
83
165
|
end
|
84
166
|
|
85
167
|
describe '#stop' do
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
168
|
+
context "with default options" do
|
169
|
+
it "stops correctly with notification" do
|
170
|
+
expect(Guard::Notifier).to receive(:notify).with('Until next time...', anything)
|
171
|
+
expect(guard.runner).to receive(:halt).once
|
172
|
+
guard.stop
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with custom :notifications option" do
|
177
|
+
let(:options) { { :notifications => [] } }
|
178
|
+
|
179
|
+
it "stops correctly without notification" do
|
180
|
+
expect(Guard::Notifier).not_to receive(:notify)
|
181
|
+
expect(guard.runner).to receive(:halt).once
|
182
|
+
guard.stop
|
183
|
+
end
|
90
184
|
end
|
91
185
|
end
|
92
186
|
|
93
|
-
describe '#
|
187
|
+
describe '#run_on_changes' do
|
94
188
|
it "reloads on change" do
|
95
189
|
expect(guard).to receive(:reload).once
|
96
|
-
guard.
|
190
|
+
guard.run_on_changes([])
|
97
191
|
end
|
98
192
|
end
|
99
193
|
end
|
100
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guard-puma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesse Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: guard
|