ballast 1.0.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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis-gemfile +15 -0
  4. data/.travis.yml +7 -0
  5. data/.yardopts +1 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Gemfile +21 -0
  8. data/README.md +40 -0
  9. data/Rakefile +28 -0
  10. data/ballast.gemspec +35 -0
  11. data/doc/Ballast/Concerns/Ajax.html +806 -0
  12. data/doc/Ballast/Concerns/Common.html +900 -0
  13. data/doc/Ballast/Concerns/ErrorsHandling.html +283 -0
  14. data/doc/Ballast/Concerns/View.html +664 -0
  15. data/doc/Ballast/Concerns.html +127 -0
  16. data/doc/Ballast/Context.html +417 -0
  17. data/doc/Ballast/Errors/BaseError.html +326 -0
  18. data/doc/Ballast/Errors/InvalidDomain.html +157 -0
  19. data/doc/Ballast/Errors/PerformError.html +157 -0
  20. data/doc/Ballast/Errors/ValidationError.html +157 -0
  21. data/doc/Ballast/Errors.html +125 -0
  22. data/doc/Ballast/Operation.html +1304 -0
  23. data/doc/Ballast/OperationsChain.html +585 -0
  24. data/doc/Ballast/Version.html +189 -0
  25. data/doc/Ballast.html +130 -0
  26. data/doc/_index.html +267 -0
  27. data/doc/class_list.html +54 -0
  28. data/doc/css/common.css +1 -0
  29. data/doc/css/full_list.css +57 -0
  30. data/doc/css/style.css +338 -0
  31. data/doc/file.README.html +115 -0
  32. data/doc/file_list.html +56 -0
  33. data/doc/frames.html +26 -0
  34. data/doc/index.html +115 -0
  35. data/doc/js/app.js +219 -0
  36. data/doc/js/full_list.js +178 -0
  37. data/doc/js/jquery.js +4 -0
  38. data/doc/method_list.html +269 -0
  39. data/doc/top-level-namespace.html +112 -0
  40. data/lib/ballast/concerns/ajax.rb +116 -0
  41. data/lib/ballast/concerns/common.rb +97 -0
  42. data/lib/ballast/concerns/errors_handling.rb +49 -0
  43. data/lib/ballast/concerns/view.rb +63 -0
  44. data/lib/ballast/context.rb +38 -0
  45. data/lib/ballast/errors.rb +34 -0
  46. data/lib/ballast/operation.rb +136 -0
  47. data/lib/ballast/operations_chain.rb +38 -0
  48. data/lib/ballast/version.rb +24 -0
  49. data/lib/ballast.rb +24 -0
  50. data/spec/ballast/concerns/ajax_spec.rb +124 -0
  51. data/spec/ballast/concerns/common_spec.rb +100 -0
  52. data/spec/ballast/concerns/errors_handling_spec.rb +63 -0
  53. data/spec/ballast/concerns/view_spec.rb +107 -0
  54. data/spec/ballast/context_spec.rb +23 -0
  55. data/spec/ballast/errors_spec.rb +16 -0
  56. data/spec/ballast/operation_spec.rb +175 -0
  57. data/spec/ballast/operations_chain_spec.rb +33 -0
  58. data/spec/coverage_helper.rb +19 -0
  59. data/spec/spec_helper.rb +19 -0
  60. metadata +225 -0
@@ -0,0 +1,900 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Module: Ballast::Concerns::Common
8
+
9
+ &mdash; Documentation by YARD 0.8.7.3
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '../../';
20
+ framesUrl = "../../frames.html#!" + escape(window.location.href);
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="../../_index.html">Index (C)</a> &raquo;
35
+ <span class='title'><span class='object_link'><a href="../../Ballast.html" title="Ballast (module)">Ballast</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Concerns.html" title="Ballast::Concerns (module)">Concerns</a></span></span>
36
+ &raquo;
37
+ <span class="title">Common</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="../../class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="../../method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="../../file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Module: Ballast::Concerns::Common
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ <dt class="r1 last">Defined in:</dt>
82
+ <dd class="r1 last">lib/ballast/concerns/common.rb</dd>
83
+
84
+ </dl>
85
+ <div class="clear"></div>
86
+
87
+ <h2>Overview</h2><div class="docstring">
88
+ <div class="discussion">
89
+ <p>A concern to handle common tasks in an application.</p>
90
+
91
+
92
+ </div>
93
+ </div>
94
+ <div class="tags">
95
+
96
+
97
+ </div>
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ <h2>
106
+ Instance Method Summary
107
+ <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
108
+ </h2>
109
+
110
+ <ul class="summary">
111
+
112
+ <li class="public ">
113
+ <span class="summary_signature">
114
+
115
+ <a href="#authenticate_user-instance_method" title="#authenticate_user (instance method)">- (Object) <strong>authenticate_user</strong>(area = nil, title = nil, message = nil, &amp;authenticator) </a>
116
+
117
+
118
+
119
+ </span>
120
+
121
+
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+ <span class="summary_desc"><div class='inline'><p>Authenticates a user via HTTP, handling the error if the authentication failed.</p>
130
+ </div></span>
131
+
132
+ </li>
133
+
134
+
135
+ <li class="public ">
136
+ <span class="summary_signature">
137
+
138
+ <a href="#format_long_date-instance_method" title="#format_long_date (instance method)">- (Object) <strong>format_long_date</strong>(date, separator = &quot;•&quot;, format = &quot;%I:%M%p %- %b %o, %Y (%:Z)&quot;) </a>
139
+
140
+
141
+
142
+ </span>
143
+
144
+
145
+
146
+
147
+
148
+
149
+
150
+
151
+
152
+ <span class="summary_desc"><div class='inline'><p>Formats a long date.</p>
153
+ </div></span>
154
+
155
+ </li>
156
+
157
+
158
+ <li class="public ">
159
+ <span class="summary_signature">
160
+
161
+ <a href="#format_short_amount-instance_method" title="#format_short_amount (instance method)">- (String) <strong>format_short_amount</strong>(amount, suffix) </a>
162
+
163
+
164
+
165
+ </span>
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ <span class="summary_desc"><div class='inline'><p>Formats a short amount of time (less than one hour).</p>
176
+ </div></span>
177
+
178
+ </li>
179
+
180
+
181
+ <li class="public ">
182
+ <span class="summary_signature">
183
+
184
+ <a href="#format_short_duration-instance_method" title="#format_short_duration (instance method)">- (String) <strong>format_short_duration</strong>(date, reference = nil, suffix = &quot;&quot;) </a>
185
+
186
+
187
+
188
+ </span>
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+ <span class="summary_desc"><div class='inline'><p>Formats a relative date using abbreviation or short formats.</p>
199
+ </div></span>
200
+
201
+ </li>
202
+
203
+
204
+ <li class="public ">
205
+ <span class="summary_signature">
206
+
207
+ <a href="#perform_operation-instance_method" title="#perform_operation (instance method)">- (Operation) <strong>perform_operation</strong>(klass, owner = nil, **kwargs) </a>
208
+
209
+
210
+
211
+ </span>
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ <span class="summary_desc"><div class='inline'><p>Performs an operation, using itself as owner by default.</p>
222
+ </div></span>
223
+
224
+ </li>
225
+
226
+
227
+ <li class="public ">
228
+ <span class="summary_signature">
229
+
230
+ <a href="#sending_data%3F-instance_method" title="#sending_data? (instance method)">- (Boolean) <strong>sending_data?</strong> </a>
231
+
232
+
233
+
234
+ </span>
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+ <span class="summary_desc"><div class='inline'><p>Checks if the user is sending any data.</p>
245
+ </div></span>
246
+
247
+ </li>
248
+
249
+
250
+ </ul>
251
+
252
+
253
+
254
+
255
+ <div id="instance_method_details" class="method_details_list">
256
+ <h2>Instance Method Details</h2>
257
+
258
+
259
+ <div class="method_details first">
260
+ <h3 class="signature first" id="authenticate_user-instance_method">
261
+
262
+ - (<tt>Object</tt>) <strong>authenticate_user</strong>(area = nil, title = nil, message = nil, &amp;authenticator)
263
+
264
+
265
+
266
+
267
+
268
+ </h3><div class="docstring">
269
+ <div class="discussion">
270
+ <p>Authenticates a user via HTTP, handling the error if the authentication failed.</p>
271
+
272
+
273
+ </div>
274
+ </div>
275
+ <div class="tags">
276
+ <p class="tag_title">Parameters:</p>
277
+ <ul class="param">
278
+
279
+ <li>
280
+
281
+ <span class='name'>area</span>
282
+
283
+
284
+ <span class='type'>(<tt>String</tt>)</span>
285
+
286
+
287
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
288
+
289
+
290
+ &mdash;
291
+ <div class='inline'><p>The name of the area.</p>
292
+ </div>
293
+
294
+ </li>
295
+
296
+ <li>
297
+
298
+ <span class='name'>title</span>
299
+
300
+
301
+ <span class='type'>(<tt>String</tt>)</span>
302
+
303
+
304
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
305
+
306
+
307
+ &mdash;
308
+ <div class='inline'><p>A title for authentication errors.</p>
309
+ </div>
310
+
311
+ </li>
312
+
313
+ <li>
314
+
315
+ <span class='name'>message</span>
316
+
317
+
318
+ <span class='type'>(<tt>String</tt>)</span>
319
+
320
+
321
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
322
+
323
+
324
+ &mdash;
325
+ <div class='inline'><p>A message for authentication errors.</p>
326
+ </div>
327
+
328
+ </li>
329
+
330
+ <li>
331
+
332
+ <span class='name'>authenticator</span>
333
+
334
+
335
+ <span class='type'>(<tt>Proc</tt>)</span>
336
+
337
+
338
+
339
+ &mdash;
340
+ <div class='inline'><p>A block to verify if authentication is valid.</p>
341
+ </div>
342
+
343
+ </li>
344
+
345
+ </ul>
346
+
347
+
348
+ </div><table class="source_code">
349
+ <tr>
350
+ <td>
351
+ <pre class="lines">
352
+
353
+
354
+ 81
355
+ 82
356
+ 83
357
+ 84
358
+ 85
359
+ 86
360
+ 87
361
+ 88
362
+ 89
363
+ 90
364
+ 91
365
+ 92
366
+ 93
367
+ 94</pre>
368
+ </td>
369
+ <td>
370
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 81</span>
371
+
372
+ <span class='kw'>def</span> <span class='id identifier rubyid_authenticate_user'>authenticate_user</span><span class='lparen'>(</span><span class='id identifier rubyid_area'>area</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_title'>title</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_authenticator'>authenticator</span><span class='rparen'>)</span>
373
+ <span class='id identifier rubyid_area'>area</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Private Area</span><span class='tstring_end'>&quot;</span></span>
374
+ <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'>Authentication required.</span><span class='tstring_end'>&quot;</span></span>
375
+ <span class='id identifier rubyid_message'>message</span> <span class='op'>||=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>To view this resource you have to authenticate.</span><span class='tstring_end'>&quot;</span></span>
376
+ <span class='id identifier rubyid_authenticated'>authenticated</span> <span class='op'>=</span> <span class='id identifier rubyid_authenticate_with_http_basic'>authenticate_with_http_basic</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_username'>username</span><span class='comma'>,</span> <span class='id identifier rubyid_password'>password</span><span class='op'>|</span> <span class='id identifier rubyid_authenticator'>authenticator</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='id identifier rubyid_username'>username</span><span class='comma'>,</span> <span class='id identifier rubyid_password'>password</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
377
+
378
+ <span class='kw'>if</span> <span class='op'>!</span><span class='id identifier rubyid_authenticated'>authenticated</span> <span class='kw'>then</span>
379
+ <span class='id identifier rubyid_headers'>headers</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>WWW-Authenticate</span><span class='tstring_end'>&quot;</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Basic realm=\&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_area'>area</span><span class='embexpr_end'>}</span><span class='tstring_content'>\&quot;</span><span class='tstring_end'>&quot;</span></span>
380
+ <span class='ivar'>@error_title</span> <span class='op'>=</span> <span class='id identifier rubyid_title'>title</span>
381
+ <span class='ivar'>@error_code</span> <span class='op'>=</span> <span class='int'>401</span>
382
+ <span class='ivar'>@error_message</span> <span class='op'>=</span> <span class='id identifier rubyid_message'>message</span>
383
+ <span class='id identifier rubyid_handle_error'>handle_error</span>
384
+ <span class='kw'>end</span>
385
+ <span class='kw'>end</span></pre>
386
+ </td>
387
+ </tr>
388
+ </table>
389
+ </div>
390
+
391
+ <div class="method_details ">
392
+ <h3 class="signature " id="format_long_date-instance_method">
393
+
394
+ - (<tt>Object</tt>) <strong>format_long_date</strong>(date, separator = &quot;•&quot;, format = &quot;%I:%M%p %- %b %o, %Y (%:Z)&quot;)
395
+
396
+
397
+
398
+
399
+
400
+ </h3><div class="docstring">
401
+ <div class="discussion">
402
+ <p>Formats a long date.</p>
403
+
404
+
405
+ </div>
406
+ </div>
407
+ <div class="tags">
408
+ <p class="tag_title">Parameters:</p>
409
+ <ul class="param">
410
+
411
+ <li>
412
+
413
+ <span class='name'>date</span>
414
+
415
+
416
+ <span class='type'>(<tt>DateTime</tt>)</span>
417
+
418
+
419
+
420
+ &mdash;
421
+ <div class='inline'><p>The date to format.</p>
422
+ </div>
423
+
424
+ </li>
425
+
426
+ <li>
427
+
428
+ <span class='name'>separator</span>
429
+
430
+
431
+ <span class='type'>(<tt>String</tt>)</span>
432
+
433
+
434
+ <em class="default">(defaults to: <tt>&quot;•&quot;</tt>)</em>
435
+
436
+
437
+ &mdash;
438
+ <div class='inline'><p>The separator between date and time.</p>
439
+ </div>
440
+
441
+ </li>
442
+
443
+ <li>
444
+
445
+ <span class='name'>format</span>
446
+
447
+
448
+ <span class='type'>(<tt>String</tt>)</span>
449
+
450
+
451
+ <em class="default">(defaults to: <tt>&quot;%I:%M%p %- %b %o, %Y (%:Z)&quot;</tt>)</em>
452
+
453
+
454
+ &mdash;
455
+ <div class='inline'><p>The format of the date, like in strftime. Use <code>%-</code> for the separator, <code>%o</code> for the ordinalized version of the day of the month
456
+ and <code>%:Z</code> for the zone name considering also DST.</p>
457
+ </div>
458
+
459
+ </li>
460
+
461
+ </ul>
462
+
463
+
464
+ </div><table class="source_code">
465
+ <tr>
466
+ <td>
467
+ <pre class="lines">
468
+
469
+
470
+ 69
471
+ 70
472
+ 71
473
+ 72
474
+ 73</pre>
475
+ </td>
476
+ <td>
477
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 69</span>
478
+
479
+ <span class='kw'>def</span> <span class='id identifier rubyid_format_long_date'>format_long_date</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='id identifier rubyid_separator'>separator</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>•</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='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%I:%M%p %- %b %o, %Y (%:Z)</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
480
+ <span class='id identifier rubyid_tz'>tz</span> <span class='op'>=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_zone'>zone</span>
481
+ <span class='id identifier rubyid_replacements'>replacements</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%-</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_separator'>separator</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%o</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_day'>day</span><span class='period'>.</span><span class='id identifier rubyid_ordinalize'>ordinalize</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%:Z</span><span class='tstring_end'>&quot;</span></span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_tz'>tz</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='id identifier rubyid_tz'>tz</span><span class='period'>.</span><span class='id identifier rubyid_uses_dst?'>uses_dst?</span> <span class='op'>&amp;&amp;</span> <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_dst?'>dst?</span> <span class='op'>?</span> <span class='symbol'>:dst_name</span> <span class='op'>:</span> <span class='symbol'>:name</span><span class='rparen'>)</span><span class='rbrace'>}</span>
482
+ <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='id identifier rubyid_format'>format</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>%(-|o|(:Z))</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_r'>r</span><span class='op'>|</span> <span class='id identifier rubyid_replacements'>replacements</span><span class='period'>.</span><span class='id identifier rubyid_fetch'>fetch</span><span class='lparen'>(</span><span class='id identifier rubyid_r'>r</span><span class='comma'>,</span> <span class='id identifier rubyid_r'>r</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
483
+ <span class='kw'>end</span></pre>
484
+ </td>
485
+ </tr>
486
+ </table>
487
+ </div>
488
+
489
+ <div class="method_details ">
490
+ <h3 class="signature " id="format_short_amount-instance_method">
491
+
492
+ - (<tt>String</tt>) <strong>format_short_amount</strong>(amount, suffix)
493
+
494
+
495
+
496
+
497
+
498
+ </h3><div class="docstring">
499
+ <div class="discussion">
500
+ <p>Formats a short amount of time (less than one hour).</p>
501
+
502
+
503
+ </div>
504
+ </div>
505
+ <div class="tags">
506
+ <p class="tag_title">Parameters:</p>
507
+ <ul class="param">
508
+
509
+ <li>
510
+
511
+ <span class='name'>amount</span>
512
+
513
+
514
+ <span class='type'>(<tt>Fixnum</tt>)</span>
515
+
516
+
517
+
518
+ &mdash;
519
+ <div class='inline'><p>The amount to format.</p>
520
+ </div>
521
+
522
+ </li>
523
+
524
+ <li>
525
+
526
+ <span class='name'>suffix</span>
527
+
528
+
529
+ <span class='type'>(<tt>String</tt>)</span>
530
+
531
+
532
+
533
+ &mdash;
534
+ <div class='inline'><p>The suffix to add to the formatted amount.</p>
535
+ </div>
536
+
537
+ </li>
538
+
539
+ </ul>
540
+
541
+ <p class="tag_title">Returns:</p>
542
+ <ul class="return">
543
+
544
+ <li>
545
+
546
+
547
+ <span class='type'>(<tt>String</tt>)</span>
548
+
549
+
550
+
551
+ &mdash;
552
+ <div class='inline'><p>The formatted amount.</p>
553
+ </div>
554
+
555
+ </li>
556
+
557
+ </ul>
558
+
559
+ </div><table class="source_code">
560
+ <tr>
561
+ <td>
562
+ <pre class="lines">
563
+
564
+
565
+ 53
566
+ 54
567
+ 55
568
+ 56
569
+ 57
570
+ 58
571
+ 59
572
+ 60
573
+ 61</pre>
574
+ </td>
575
+ <td>
576
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 53</span>
577
+
578
+ <span class='kw'>def</span> <span class='id identifier rubyid_format_short_amount'>format_short_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_suffix'>suffix</span><span class='rparen'>)</span>
579
+ <span class='kw'>if</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>&lt;</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_minute'>minute</span> <span class='kw'>then</span>
580
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_amount'>amount</span><span class='period'>.</span><span class='id identifier rubyid_floor'>floor</span><span class='embexpr_end'>}</span><span class='tstring_content'>s</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_suffix'>suffix</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
581
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>&lt;</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_hour'>hour</span> <span class='kw'>then</span>
582
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>/</span> <span class='int'>60</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_floor'>floor</span><span class='embexpr_end'>}</span><span class='tstring_content'>m</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_suffix'>suffix</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
583
+ <span class='kw'>else</span>
584
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='embexpr_beg'>#{</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span> <span class='op'>/</span> <span class='int'>3600</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_floor'>floor</span><span class='embexpr_end'>}</span><span class='tstring_content'>h</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_suffix'>suffix</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
585
+ <span class='kw'>end</span>
586
+ <span class='kw'>end</span></pre>
587
+ </td>
588
+ </tr>
589
+ </table>
590
+ </div>
591
+
592
+ <div class="method_details ">
593
+ <h3 class="signature " id="format_short_duration-instance_method">
594
+
595
+ - (<tt>String</tt>) <strong>format_short_duration</strong>(date, reference = nil, suffix = &quot;&quot;)
596
+
597
+
598
+
599
+
600
+
601
+ </h3><div class="docstring">
602
+ <div class="discussion">
603
+ <p>Formats a relative date using abbreviation or short formats.</p>
604
+
605
+
606
+ </div>
607
+ </div>
608
+ <div class="tags">
609
+ <p class="tag_title">Parameters:</p>
610
+ <ul class="param">
611
+
612
+ <li>
613
+
614
+ <span class='name'>date</span>
615
+
616
+
617
+ <span class='type'>(<tt>DateTime</tt>)</span>
618
+
619
+
620
+
621
+ &mdash;
622
+ <div class='inline'><p>The date to format.</p>
623
+ </div>
624
+
625
+ </li>
626
+
627
+ <li>
628
+
629
+ <span class='name'>reference</span>
630
+
631
+
632
+ <span class='type'>(<tt>DateTime</tt>)</span>
633
+
634
+
635
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
636
+
637
+
638
+ &mdash;
639
+ <div class='inline'><p>The reference date.</p>
640
+ </div>
641
+
642
+ </li>
643
+
644
+ <li>
645
+
646
+ <span class='name'>suffix</span>
647
+
648
+
649
+ <span class='type'>(<tt>String</tt>)</span>
650
+
651
+
652
+ <em class="default">(defaults to: <tt>&quot;&quot;</tt>)</em>
653
+
654
+
655
+ &mdash;
656
+ <div class='inline'><p>The suffix to add to the formatted date.</p>
657
+ </div>
658
+
659
+ </li>
660
+
661
+ </ul>
662
+
663
+ <p class="tag_title">Returns:</p>
664
+ <ul class="return">
665
+
666
+ <li>
667
+
668
+
669
+ <span class='type'>(<tt>String</tt>)</span>
670
+
671
+
672
+
673
+ &mdash;
674
+ <div class='inline'><p>The formatted date.</p>
675
+ </div>
676
+
677
+ </li>
678
+
679
+ </ul>
680
+
681
+ </div><table class="source_code">
682
+ <tr>
683
+ <td>
684
+ <pre class="lines">
685
+
686
+
687
+ 33
688
+ 34
689
+ 35
690
+ 36
691
+ 37
692
+ 38
693
+ 39
694
+ 40
695
+ 41
696
+ 42
697
+ 43
698
+ 44
699
+ 45
700
+ 46</pre>
701
+ </td>
702
+ <td>
703
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 33</span>
704
+
705
+ <span class='kw'>def</span> <span class='id identifier rubyid_format_short_duration'>format_short_duration</span><span class='lparen'>(</span><span class='id identifier rubyid_date'>date</span><span class='comma'>,</span> <span class='id identifier rubyid_reference'>reference</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='id identifier rubyid_suffix'>suffix</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
706
+ <span class='id identifier rubyid_reference'>reference</span> <span class='op'>||=</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_now'>now</span>
707
+ <span class='id identifier rubyid_amount'>amount</span> <span class='op'>=</span> <span class='lparen'>(</span><span class='id identifier rubyid_reference'>reference</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span> <span class='op'>-</span> <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_to_i'>to_i</span>
708
+
709
+ <span class='kw'>if</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>&lt;=</span> <span class='int'>0</span> <span class='kw'>then</span>
710
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>now</span><span class='tstring_end'>&quot;</span></span>
711
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>&lt;</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_day'>day</span> <span class='kw'>then</span>
712
+ <span class='id identifier rubyid_format_short_amount'>format_short_amount</span><span class='lparen'>(</span><span class='id identifier rubyid_amount'>amount</span><span class='comma'>,</span> <span class='id identifier rubyid_suffix'>suffix</span><span class='rparen'>)</span>
713
+ <span class='kw'>elsif</span> <span class='id identifier rubyid_amount'>amount</span> <span class='op'>&lt;</span> <span class='int'>1</span><span class='period'>.</span><span class='id identifier rubyid_year'>year</span> <span class='kw'>then</span>
714
+ <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%b %d</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
715
+ <span class='kw'>else</span>
716
+ <span class='id identifier rubyid_date'>date</span><span class='period'>.</span><span class='id identifier rubyid_strftime'>strftime</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>%b %d %Y</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
717
+ <span class='kw'>end</span>
718
+ <span class='kw'>end</span></pre>
719
+ </td>
720
+ </tr>
721
+ </table>
722
+ </div>
723
+
724
+ <div class="method_details ">
725
+ <h3 class="signature " id="perform_operation-instance_method">
726
+
727
+ - (<tt><span class='object_link'><a href="../Operation.html" title="Ballast::Operation (class)">Operation</a></span></tt>) <strong>perform_operation</strong>(klass, owner = nil, **kwargs)
728
+
729
+
730
+
731
+
732
+
733
+ </h3><div class="docstring">
734
+ <div class="discussion">
735
+ <p>Performs an operation, using itself as owner by default.</p>
736
+
737
+
738
+ </div>
739
+ </div>
740
+ <div class="tags">
741
+ <p class="tag_title">Parameters:</p>
742
+ <ul class="param">
743
+
744
+ <li>
745
+
746
+ <span class='name'>klass</span>
747
+
748
+
749
+ <span class='type'>(<tt>Class</tt>)</span>
750
+
751
+
752
+
753
+ &mdash;
754
+ <div class='inline'><p>The operation to perform.</p>
755
+ </div>
756
+
757
+ </li>
758
+
759
+ <li>
760
+
761
+ <span class='name'>owner</span>
762
+
763
+
764
+ <span class='type'>(<tt>Object</tt>)</span>
765
+
766
+
767
+ <em class="default">(defaults to: <tt>nil</tt>)</em>
768
+
769
+
770
+ &mdash;
771
+ <div class='inline'><p>The owner to use. By default it uses itself.</p>
772
+ </div>
773
+
774
+ </li>
775
+
776
+ <li>
777
+
778
+ <span class='name'>kwargs</span>
779
+
780
+
781
+ <span class='type'>(<tt>Hash</tt>)</span>
782
+
783
+
784
+
785
+ &mdash;
786
+ <div class='inline'><p>The arguments for performing.</p>
787
+ </div>
788
+
789
+ </li>
790
+
791
+ </ul>
792
+
793
+ <p class="tag_title">Returns:</p>
794
+ <ul class="return">
795
+
796
+ <li>
797
+
798
+
799
+ <span class='type'>(<tt><span class='object_link'><a href="../Operation.html" title="Ballast::Operation (class)">Operation</a></span></tt>)</span>
800
+
801
+
802
+
803
+ &mdash;
804
+ <div class='inline'><p>The performed operation</p>
805
+ </div>
806
+
807
+ </li>
808
+
809
+ </ul>
810
+
811
+ </div><table class="source_code">
812
+ <tr>
813
+ <td>
814
+ <pre class="lines">
815
+
816
+
817
+ 23
818
+ 24
819
+ 25</pre>
820
+ </td>
821
+ <td>
822
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 23</span>
823
+
824
+ <span class='kw'>def</span> <span class='id identifier rubyid_perform_operation'>perform_operation</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span> <span class='id identifier rubyid_owner'>owner</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
825
+ <span class='ivar'>@operation</span> <span class='op'>=</span> <span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_perform'>perform</span><span class='lparen'>(</span><span class='id identifier rubyid_owner'>owner</span> <span class='op'>||</span> <span class='kw'>self</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_kwargs'>kwargs</span><span class='rparen'>)</span>
826
+ <span class='kw'>end</span></pre>
827
+ </td>
828
+ </tr>
829
+ </table>
830
+ </div>
831
+
832
+ <div class="method_details ">
833
+ <h3 class="signature " id="sending_data?-instance_method">
834
+
835
+ - (<tt>Boolean</tt>) <strong>sending_data?</strong>
836
+
837
+
838
+
839
+
840
+
841
+ </h3><div class="docstring">
842
+ <div class="discussion">
843
+ <p>Checks if the user is sending any data.</p>
844
+
845
+
846
+ </div>
847
+ </div>
848
+ <div class="tags">
849
+
850
+ <p class="tag_title">Returns:</p>
851
+ <ul class="return">
852
+
853
+ <li>
854
+
855
+
856
+ <span class='type'>(<tt>Boolean</tt>)</span>
857
+
858
+
859
+
860
+ &mdash;
861
+ <div class='inline'><p><code>true</code> if the user is sending data, <code>false</code> otherwise.</p>
862
+ </div>
863
+
864
+ </li>
865
+
866
+ </ul>
867
+
868
+ </div><table class="source_code">
869
+ <tr>
870
+ <td>
871
+ <pre class="lines">
872
+
873
+
874
+ 13
875
+ 14
876
+ 15</pre>
877
+ </td>
878
+ <td>
879
+ <pre class="code"><span class="info file"># File 'lib/ballast/concerns/common.rb', line 13</span>
880
+
881
+ <span class='kw'>def</span> <span class='id identifier rubyid_sending_data?'>sending_data?</span>
882
+ <span class='id identifier rubyid_request'>request</span><span class='period'>.</span><span class='id identifier rubyid_post?'>post?</span> <span class='op'>||</span> <span class='id identifier rubyid_request'>request</span><span class='period'>.</span><span class='id identifier rubyid_put?'>put?</span>
883
+ <span class='kw'>end</span></pre>
884
+ </td>
885
+ </tr>
886
+ </table>
887
+ </div>
888
+
889
+ </div>
890
+
891
+ </div>
892
+
893
+ <div id="footer">
894
+ Generated on Wed Dec 25 11:35:22 2013 by
895
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
896
+ 0.8.7.3 (ruby-2.0.0).
897
+ </div>
898
+
899
+ </body>
900
+ </html>