ballast 1.3.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d3677739c7345fff51757aa4480042825e1933c2
4
- data.tar.gz: baa5609857d7f710b8a771e684fff697d4acf049
3
+ metadata.gz: 39130e71a76171f367bfcc3263dddfe12b93d992
4
+ data.tar.gz: cddecb3d31027a9257dccce575148d2429c2e3bc
5
5
  SHA512:
6
- metadata.gz: a530c3ccf4f1b983497b5f281cbae6dbc266e5c21f8b51db3350203270706767129de7f291126023dcabd63b2272fe6bb80acbfee411aac87496726657628fa5
7
- data.tar.gz: 06cf71b6ebcdc5797a46a812353fc540156ad4a236998b55c65dd81d14bb01e0c4a0a1b3e9efbdc42548be2c3267cfaef5cf2f0a64d666212b79727b0426cace
6
+ metadata.gz: 04956f35bcf407f268c0dd1f28597339efd9d26e5f7e922db4574ab2b80e3bf6c9ac3ac5a35c29365acd791b4c4f25ecf5495ef18f637b3c8be899e54ed56ff8
7
+ data.tar.gz: c30ff322b3214a2fa39573bc059c06b44058bdc555a5074845173c7881dcf799ff1bd207fedd3c6ad9f9f2797de3944aa72f68147250ec9d05169f1f4f9144ce
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ### 1.4.0 / 2013-12-30
2
+
3
+ * Added format parameter to ErrorsHandling#handle_error.
4
+
1
5
  ### 1.3.0 / 2013-12-30
2
6
 
3
7
  * Added ApplicationConfiguration class.
@@ -797,7 +797,7 @@
797
797
  </div>
798
798
 
799
799
  <div id="footer">
800
- Generated on Mon Dec 30 12:53:19 2013 by
800
+ Generated on Sat Jan 4 10:09:07 2014 by
801
801
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
802
802
  0.8.7.3 (ruby-2.1.0).
803
803
  </div>
@@ -887,7 +887,7 @@ and <code>%:Z</code> for the zone name considering also DST.</p>
887
887
  </div>
888
888
 
889
889
  <div id="footer">
890
- Generated on Mon Dec 30 12:53:19 2013 by
890
+ Generated on Sat Jan 4 10:09:07 2014 by
891
891
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
892
892
  0.8.7.3 (ruby-2.1.0).
893
893
  </div>
@@ -116,7 +116,7 @@
116
116
  <li class="public ">
117
117
  <span class="summary_signature">
118
118
 
119
- <a href="#handle_error-instance_method" title="#handle_error (instance method)">- (Object) <strong>handle_error</strong>(exception = nil, layout = &quot;error&quot;, title = &quot;Error - Application&quot;) </a>
119
+ <a href="#handle_error-instance_method" title="#handle_error (instance method)">- (Object) <strong>handle_error</strong>(exception = nil, layout = &quot;error&quot;, title = &quot;Error - Application&quot;, format = nil) </a>
120
120
 
121
121
 
122
122
 
@@ -149,7 +149,7 @@
149
149
  <div class="method_details first">
150
150
  <h3 class="signature first" id="handle_error-instance_method">
151
151
 
152
- - (<tt>Object</tt>) <strong>handle_error</strong>(exception = nil, layout = &quot;error&quot;, title = &quot;Error - Application&quot;)
152
+ - (<tt>Object</tt>) <strong>handle_error</strong>(exception = nil, layout = &quot;error&quot;, title = &quot;Error - Application&quot;, format = nil)
153
153
 
154
154
 
155
155
 
@@ -217,6 +217,23 @@
217
217
 
218
218
  </li>
219
219
 
220
+ <li>
221
+
222
+ <span class='name'>format</span>
223
+
224
+
225
+ <span class='type'>(<tt>String|Symbol</tt>)</span>
226
+
227
+
228
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
229
+
230
+
231
+ &mdash;
232
+ <div class='inline'><p>The format of the response.</p>
233
+ </div>
234
+
235
+ </li>
236
+
220
237
  </ul>
221
238
 
222
239
 
@@ -226,7 +243,6 @@
226
243
  <pre class="lines">
227
244
 
228
245
 
229
- 17
230
246
  18
231
247
  19
232
248
  20
@@ -242,12 +258,13 @@
242
258
  30
243
259
  31
244
260
  32
245
- 33</pre>
261
+ 33
262
+ 34</pre>
246
263
  </td>
247
264
  <td>
248
- <pre class="code"><span class="info file"># File 'lib/ballast/concerns/errors_handling.rb', line 17</span>
265
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/errors_handling.rb', line 18</span>
249
266
 
250
- <span class='kw'>def</span> <span class='id identifier rubyid_handle_error'>handle_error</span><span class='lparen'>(</span><span class='id identifier rubyid_exception'>exception</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_layout'>layout</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>error</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_title'>title</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error - Application</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
267
+ <span class='kw'>def</span> <span class='id identifier rubyid_handle_error'>handle_error</span><span class='lparen'>(</span><span class='id identifier rubyid_exception'>exception</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_layout'>layout</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>error</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_title'>title</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Error - Application</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='rparen'>)</span>
251
268
  <span class='ivar'>@error</span> <span class='op'>||=</span> <span class='id identifier rubyid_exception'>exception</span>
252
269
 
253
270
  <span class='kw'>if</span> <span class='ivar'>@error</span><span class='period'>.</span><span class='id identifier rubyid_is_a?'>is_a?</span><span class='lparen'>(</span><span class='const'>Lazier</span><span class='op'>::</span><span class='const'>Exceptions</span><span class='op'>::</span><span class='const'>Debug</span><span class='rparen'>)</span> <span class='kw'>then</span>
@@ -262,7 +279,7 @@
262
279
  <span class='ivar'>@error_code</span> <span class='op'>=</span> <span class='int'>500</span>
263
280
  <span class='kw'>end</span>
264
281
 
265
- <span class='id identifier rubyid_send_or_render_error'>send_or_render_error</span><span class='lparen'>(</span><span class='id identifier rubyid_layout'>layout</span><span class='rparen'>)</span>
282
+ <span class='id identifier rubyid_send_or_render_error'>send_or_render_error</span><span class='lparen'>(</span><span class='id identifier rubyid_layout'>layout</span><span class='comma'>,</span> <span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span>
266
283
  <span class='kw'>end</span></pre>
267
284
  </td>
268
285
  </tr>
@@ -274,7 +291,7 @@
274
291
  </div>
275
292
 
276
293
  <div id="footer">
277
- Generated on Mon Dec 30 12:53:19 2013 by
294
+ Generated on Sat Jan 4 10:09:07 2014 by
278
295
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
279
296
  0.8.7.3 (ruby-2.1.0).
280
297
  </div>
@@ -638,7 +638,7 @@
638
638
  </div>
639
639
 
640
640
  <div id="footer">
641
- Generated on Mon Dec 30 12:53:18 2013 by
641
+ Generated on Sat Jan 4 10:09:07 2014 by
642
642
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
643
643
  0.8.7.3 (ruby-2.1.0).
644
644
  </div>
@@ -118,7 +118,7 @@
118
118
  </div>
119
119
 
120
120
  <div id="footer">
121
- Generated on Mon Dec 30 12:53:18 2013 by
121
+ Generated on Sat Jan 4 10:09:07 2014 by
122
122
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
123
123
  0.8.7.3 (ruby-2.1.0).
124
124
  </div>
@@ -273,7 +273,7 @@ Subfolders are not supported.</p>
273
273
  </div>
274
274
 
275
275
  <div id="footer">
276
- Generated on Mon Dec 30 12:53:19 2013 by
276
+ Generated on Sat Jan 4 10:09:07 2014 by
277
277
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
278
278
  0.8.7.3 (ruby-2.1.0).
279
279
  </div>
@@ -408,7 +408,7 @@
408
408
  </div>
409
409
 
410
410
  <div id="footer">
411
- Generated on Mon Dec 30 12:53:19 2013 by
411
+ Generated on Sat Jan 4 10:09:07 2014 by
412
412
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
413
413
  0.8.7.3 (ruby-2.1.0).
414
414
  </div>
@@ -317,7 +317,7 @@
317
317
  </div>
318
318
 
319
319
  <div id="footer">
320
- Generated on Mon Dec 30 12:53:19 2013 by
320
+ Generated on Sat Jan 4 10:09:07 2014 by
321
321
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
322
322
  0.8.7.3 (ruby-2.1.0).
323
323
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Mon Dec 30 12:53:19 2013 by
151
+ Generated on Sat Jan 4 10:09:07 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Mon Dec 30 12:53:19 2013 by
151
+ Generated on Sat Jan 4 10:09:07 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -148,7 +148,7 @@
148
148
  </div>
149
149
 
150
150
  <div id="footer">
151
- Generated on Mon Dec 30 12:53:19 2013 by
151
+ Generated on Sat Jan 4 10:09:07 2014 by
152
152
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
153
153
  0.8.7.3 (ruby-2.1.0).
154
154
  </div>
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Mon Dec 30 12:53:18 2013 by
119
+ Generated on Sat Jan 4 10:09:07 2014 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.8.7.3 (ruby-2.1.0).
122
122
  </div>
@@ -345,7 +345,7 @@
345
345
  </div>
346
346
 
347
347
  <div id="footer">
348
- Generated on Mon Dec 30 12:53:19 2013 by
348
+ Generated on Sat Jan 4 10:09:07 2014 by
349
349
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
350
350
  0.8.7.3 (ruby-2.1.0).
351
351
  </div>
@@ -116,7 +116,7 @@
116
116
  </div>
117
117
 
118
118
  <div id="footer">
119
- Generated on Mon Dec 30 12:53:19 2013 by
119
+ Generated on Sat Jan 4 10:09:07 2014 by
120
120
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
121
121
  0.8.7.3 (ruby-2.1.0).
122
122
  </div>
@@ -1295,7 +1295,7 @@ as owner will be created.</p>
1295
1295
  </div>
1296
1296
 
1297
1297
  <div id="footer">
1298
- Generated on Mon Dec 30 12:53:19 2013 by
1298
+ Generated on Sat Jan 4 10:09:07 2014 by
1299
1299
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
1300
1300
  0.8.7.3 (ruby-2.1.0).
1301
1301
  </div>
@@ -576,7 +576,7 @@ as owner will be created.</p>
576
576
  </div>
577
577
 
578
578
  <div id="footer">
579
- Generated on Mon Dec 30 12:53:19 2013 by
579
+ Generated on Sat Jan 4 10:09:07 2014 by
580
580
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
581
581
  0.8.7.3 (ruby-2.1.0).
582
582
  </div>
@@ -908,7 +908,7 @@
908
908
  </div>
909
909
 
910
910
  <div id="footer">
911
- Generated on Mon Dec 30 12:53:19 2013 by
911
+ Generated on Sat Jan 4 10:09:07 2014 by
912
912
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
913
913
  0.8.7.3 (ruby-2.1.0).
914
914
  </div>
@@ -134,7 +134,7 @@
134
134
 
135
135
  </div>
136
136
  </dt>
137
- <dd><pre class="code"><span class='int'>3</span></pre></dd>
137
+ <dd><pre class="code"><span class='int'>4</span></pre></dd>
138
138
 
139
139
  <dt id="PATCH-constant" class="">PATCH =
140
140
  <div class="docstring">
@@ -180,7 +180,7 @@
180
180
  </div>
181
181
 
182
182
  <div id="footer">
183
- Generated on Mon Dec 30 12:53:18 2013 by
183
+ Generated on Sat Jan 4 10:09:07 2014 by
184
184
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
185
185
  0.8.7.3 (ruby-2.1.0).
186
186
  </div>
data/doc/Ballast.html CHANGED
@@ -121,7 +121,7 @@ Licensed under the MIT license, which can be found at http://www.opensource.org/
121
121
  </div>
122
122
 
123
123
  <div id="footer">
124
- Generated on Mon Dec 30 12:53:18 2013 by
124
+ Generated on Sat Jan 4 10:09:07 2014 by
125
125
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
126
126
  0.8.7.3 (ruby-2.1.0).
127
127
  </div>
data/doc/_index.html CHANGED
@@ -310,7 +310,7 @@
310
310
  </div>
311
311
 
312
312
  <div id="footer">
313
- Generated on Mon Dec 30 12:53:17 2013 by
313
+ Generated on Sat Jan 4 10:09:06 2014 by
314
314
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
315
315
  0.8.7.3 (ruby-2.1.0).
316
316
  </div>
data/doc/file.README.html CHANGED
@@ -106,7 +106,7 @@
106
106
  </div></div>
107
107
 
108
108
  <div id="footer">
109
- Generated on Mon Dec 30 12:53:18 2013 by
109
+ Generated on Sat Jan 4 10:09:06 2014 by
110
110
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
111
  0.8.7.3 (ruby-2.1.0).
112
112
  </div>
data/doc/index.html CHANGED
@@ -106,7 +106,7 @@
106
106
  </div></div>
107
107
 
108
108
  <div id="footer">
109
- Generated on Mon Dec 30 12:53:18 2013 by
109
+ Generated on Sat Jan 4 10:09:06 2014 by
110
110
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
111
  0.8.7.3 (ruby-2.1.0).
112
112
  </div>
@@ -103,7 +103,7 @@
103
103
  </div>
104
104
 
105
105
  <div id="footer">
106
- Generated on Mon Dec 30 12:53:18 2013 by
106
+ Generated on Sat Jan 4 10:09:06 2014 by
107
107
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
108
108
  0.8.7.3 (ruby-2.1.0).
109
109
  </div>
@@ -14,7 +14,8 @@ module Ballast
14
14
  # @param exception [Hash|Exception] The exception to handle.
15
15
  # @param layout [String] The layout to use to render the error.
16
16
  # @param title [String] The title to set in case of custom errors.
17
- def handle_error(exception = nil, layout = "error", title = "Error - Application")
17
+ # @param format [String|Symbol] The format of the response.
18
+ def handle_error(exception = nil, layout = "error", title = "Error - Application", format = nil)
18
19
  @error ||= exception
19
20
 
20
21
  if @error.is_a?(Lazier::Exceptions::Debug) then
@@ -29,17 +30,22 @@ module Ballast
29
30
  @error_code = 500
30
31
  end
31
32
 
32
- send_or_render_error(layout)
33
+ send_or_render_error(layout, format)
33
34
  end
34
35
 
35
36
  private
36
37
  # Send an AJAX error o renders it.
37
38
  #
38
39
  # @param layout [String] The layout to use to render the error.
39
- def send_or_render_error(layout)
40
- if is_ajax? then
41
- data = prepare_ajax(@error_code, {type: @error_title, backtrace: @error.backtrace.join("\n")}, @error_message || @error.message)
42
- send_ajax(data)
40
+ # @param format [String|Symbol] The format of the response.
41
+ def send_or_render_error(layout, format = nil)
42
+ format ||= request.format.to_sym
43
+
44
+ if is_ajax? || format.to_s =~ /^json/ then
45
+ details = {type: @error_title}
46
+ details[:backtrace] = @error.backtrace.join("\n") if @error.respond_to?(:backtrace)
47
+ data = prepare_ajax(@error_code, details, @error_message || @error.message)
48
+ send_ajax(data, format: format)
43
49
  else
44
50
  render(nothing: true, status: @error_code, layout: layout, formats: [:html])
45
51
  end
@@ -13,7 +13,7 @@ module Ballast
13
13
  MAJOR = 1
14
14
 
15
15
  # The minor version.
16
- MINOR = 3
16
+ MINOR = 4
17
17
 
18
18
  # The patch version.
19
19
  PATCH = 0
@@ -21,7 +21,7 @@ describe Ballast::Concerns::ErrorsHandling do
21
21
  describe "#handle_error" do
22
22
  it "should handle a custom error" do
23
23
  error = {status: "STATUS", error: "ERROR"}
24
- expect(subject).to receive(:send_or_render_error).with("LAYOUT")
24
+ expect(subject).to receive(:send_or_render_error).with("LAYOUT", nil)
25
25
  subject.handle_error(error, "LAYOUT", "TITLE")
26
26
 
27
27
  expect(subject.instance_variable_get(:@error)).to eq(error)
@@ -50,12 +50,19 @@ describe Ballast::Concerns::ErrorsHandling do
50
50
 
51
51
  it "should render an AJAX error" do
52
52
  expect_any_instance_of(RuntimeError).to receive(:backtrace).and_return(["A", "B"])
53
- expect(subject).to receive(:is_ajax?).and_return(true)
54
- expect(subject).to receive(:send_ajax).with({status: 500, error: "ERROR", data: {type: "Error - RuntimeError", backtrace: "A\nB"}}.with_indifferent_access)
53
+ allow(subject).to receive(:request).and_return(OpenStruct.new(format: :json))
54
+ expect(subject).to receive(:is_ajax?).exactly(2).and_return(true, false)
55
+
56
+ expect(subject).to receive(:send_ajax).with({status: 500, error: "ERROR", data: {type: "Error - RuntimeError", backtrace: "A\nB"}}.with_indifferent_access, {format: :json})
57
+ expect(subject).to receive(:send_ajax).with({status: :forbidden, error: "ERROR", data: {type: "TITLE"}}.with_indifferent_access, {format: :json})
58
+
55
59
  subject.handle_error(RuntimeError.new("ERROR"), "LAYOUT")
60
+ subject.instance_variable_set(:@error, nil)
61
+ subject.handle_error({title: "TITLE", status: :forbidden, error: "ERROR"}, :json)
56
62
  end
57
63
 
58
64
  it "should render a HTML error" do
65
+ allow(subject).to receive(:request).and_return(OpenStruct.new(format: :html))
59
66
  expect(subject).to receive(:render).with(nothing: true, status: 500, layout: "LAYOUT", formats: [:html])
60
67
  subject.handle_error(RuntimeError.new("ERROR"), "LAYOUT")
61
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballast
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shogun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack