guard-puma 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e00ac65e68f7b4921cfa5a02bc117182de5c0d9
4
- data.tar.gz: ad040e3870595a66d6aae79cace22b5a59d6ef4f
3
+ metadata.gz: ba3c0c0435df8f3c4ebc9383ae9afbd92bd2f41d
4
+ data.tar.gz: c89ab9b1313f04b420a8ac8be2dc6a2b685f9440
5
5
  SHA512:
6
- metadata.gz: 493b03f73a243ceb4c4a8a6542d80f8e7c5be67a94b83383e80bf064f136918ddb0c37500d1eccb5cfa61a897e9432f876ef28acb87c436c733f5bd8751a2ad4
7
- data.tar.gz: 3ec94f2e799ed2a9a8148289a13673118a97c5b62d85e6d7d655b0db0f5dae85f77a2f79011244d68cec92d36df011a3b2765d857f91ebca851833179da50839
6
+ metadata.gz: f3bf2e82c1da9bdfc4ae1d78244455642b5a07f242f0af7f4998b121492214b5322d5094b9f21b538575d04d2599a93c813055d7a07e614e98f07bce176aa60a
7
+ data.tar.gz: 073f9b90a53e4aed7fd27c282d63b50ff82f54e57fec7d6579a5446d24dd539648630d0a66f99bc16f88f47ad61f27ec6c35c9a96f431bc676b00aaa8e2ec9f9
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## 0.4.1
4
+
5
+ * Improve notifications. Via #30
6
+
3
7
  ## 0.4.0
4
8
 
5
9
  * Support Windows with custom start command. Via #29
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 "Guard::Puma will now start your app on port #{options[:port]} using #{server}#{options[:environment]} environment."
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
- Notifier.notify("Puma restarting on port #{options[:port]} in #{options[:environment]} environment...", :title => "Restarting Puma...", :image => :pending)
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
- Notifier.notify("Puma restarted on port #{options[:port]}.", :title => "Puma restarted!", :image => :success)
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
- Notifier.notify("Puma NOT restarted, check your log files.", :title => "Puma NOT restarted!", :image => :failed)
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
- Notifier.notify("Until next time...", :title => "Puma shutting down.", :image => :pending)
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 run_on_change(paths)
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
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module PumaVersion
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
@@ -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::Notifier).to receive(:notify).with(/Puma restarting/, hash_including(:image => :pending))
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
- it "restarts and show the message" do
77
- expect(Guard::UI).to receive(:info)
78
- expect(Guard::Notifier).to receive(:notify).with(/Puma restarted/, hash_including(:image => :success))
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
- guard.reload
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
- it "stops correctly" do
87
- expect(Guard::Notifier).to receive(:notify).with('Until next time...', anything)
88
- expect(guard.runner).to receive(:halt).once
89
- guard.stop
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 '#run_on_change' do
187
+ describe '#run_on_changes' do
94
188
  it "reloads on change" do
95
189
  expect(guard).to receive(:reload).once
96
- guard.run_on_change([])
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.0
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: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2018-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard