simple-service 0.1.5 → 0.2.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/.rubocop.yml +10 -2
- data/Gemfile +3 -1
- data/Makefile +5 -2
- data/TODO.txt +3 -0
- data/VERSION +1 -1
- data/doc/Simple/Service/Action/Comment/Extractor.html +1 -1
- data/doc/Simple/Service/Action/Comment.html +1 -1
- data/doc/Simple/Service/Action/MethodReflection.html +1 -1
- data/doc/Simple/Service/Action/Parameter.html +2 -2
- data/doc/Simple/Service/Action.html +59 -150
- data/doc/Simple/Service/ArgumentError.html +1 -1
- data/doc/Simple/Service/ClassMethods.html +5 -5
- data/doc/Simple/Service/Context.html +5 -5
- data/doc/Simple/Service/ContextMissingError.html +1 -1
- data/doc/Simple/Service/ContextReadOnlyError.html +1 -1
- data/doc/Simple/Service/ExtraArguments.html +1 -1
- data/doc/Simple/Service/GemHelper.html +1 -1
- data/doc/Simple/Service/MissingArguments.html +1 -1
- data/doc/Simple/Service/NoSuchAction.html +1 -1
- data/doc/Simple/Service.html +89 -87
- data/doc/Simple.html +1 -1
- data/doc/_index.html +7 -19
- data/doc/class_list.html +1 -1
- data/doc/file.README.html +3 -3
- data/doc/file.TODO.html +70 -0
- data/doc/file_list.html +5 -0
- data/doc/index.html +3 -3
- data/doc/method_list.html +59 -115
- data/doc/top-level-namespace.html +1 -1
- data/lib/simple/service/action/comment.rb +1 -1
- data/lib/simple/service/action.rb +10 -3
- data/lib/simple/service/errors.rb +4 -3
- data/lib/simple/service.rb +33 -28
- data/lib/simple/workflow/context.rb +105 -0
- data/lib/simple/workflow/current_context.rb +33 -0
- data/lib/simple/workflow/reloader.rb +84 -0
- data/lib/simple/workflow/rspec_helper.rb +15 -0
- data/lib/simple/workflow.rb +96 -0
- data/lib/simple-workflow.rb +3 -0
- data/scripts/test +2 -0
- data/simple-service.gemspec +1 -0
- data/spec/simple/service/action_invoke3_spec.rb +0 -8
- data/spec/simple/service/action_invoke_spec.rb +82 -20
- data/spec/simple/service/service_spec.rb +13 -56
- data/spec/simple/workflow/context_spec.rb +90 -0
- data/spec/simple/workflow/current_context_spec.rb +41 -0
- data/spec/simple/workflow/reloader_spec/example1.rb +10 -0
- data/spec/simple/workflow/reloader_spec/example2.rb +7 -0
- data/spec/simple/workflow/reloader_spec.rb +48 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/support/spec_services.rb +1 -3
- metadata +42 -7
- data/doc/Simple/Service/Action/IndieHash.html +0 -506
- data/lib/simple/service/context.rb +0 -94
- data/spec/simple/service/context_spec.rb +0 -69
@@ -1,506 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<meta charset="utf-8">
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
-
<title>
|
7
|
-
Class: Simple::Service::Action::IndieHash
|
8
|
-
|
9
|
-
— Documentation by YARD 0.9.20
|
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
|
-
pathId = "Simple::Service::Action::IndieHash";
|
19
|
-
relpath = '../../../';
|
20
|
-
</script>
|
21
|
-
|
22
|
-
|
23
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
|
24
|
-
|
25
|
-
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
|
26
|
-
|
27
|
-
|
28
|
-
</head>
|
29
|
-
<body>
|
30
|
-
<div class="nav_wrap">
|
31
|
-
<iframe id="nav" src="../../../class_list.html?1"></iframe>
|
32
|
-
<div id="resizer"></div>
|
33
|
-
</div>
|
34
|
-
|
35
|
-
<div id="main" tabindex="-1">
|
36
|
-
<div id="header">
|
37
|
-
<div id="menu">
|
38
|
-
|
39
|
-
<a href="../../../_index.html">Index (I)</a> »
|
40
|
-
<span class='title'><span class='object_link'><a href="../../../Simple.html" title="Simple (module)">Simple</a></span></span> » <span class='title'><span class='object_link'><a href="../../Service.html" title="Simple::Service (module)">Service</a></span></span> » <span class='title'><span class='object_link'><a href="../Action.html" title="Simple::Service::Action (class)">Action</a></span></span>
|
41
|
-
»
|
42
|
-
<span class="title">IndieHash</span>
|
43
|
-
|
44
|
-
</div>
|
45
|
-
|
46
|
-
<div id="search">
|
47
|
-
|
48
|
-
<a class="full_list_link" id="class_list_link"
|
49
|
-
href="../../../class_list.html">
|
50
|
-
|
51
|
-
<svg width="24" height="24">
|
52
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
-
</svg>
|
56
|
-
</a>
|
57
|
-
|
58
|
-
</div>
|
59
|
-
<div class="clear"></div>
|
60
|
-
</div>
|
61
|
-
|
62
|
-
<div id="content"><h1>Class: Simple::Service::Action::IndieHash
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
</h1>
|
67
|
-
<div class="box_info">
|
68
|
-
|
69
|
-
<dl>
|
70
|
-
<dt>Inherits:</dt>
|
71
|
-
<dd>
|
72
|
-
<span class="inheritName">Object</span>
|
73
|
-
|
74
|
-
<ul class="fullTree">
|
75
|
-
<li>Object</li>
|
76
|
-
|
77
|
-
<li class="next">Simple::Service::Action::IndieHash</li>
|
78
|
-
|
79
|
-
</ul>
|
80
|
-
<a href="#" class="inheritanceTree">show all</a>
|
81
|
-
|
82
|
-
</dd>
|
83
|
-
</dl>
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
<dl>
|
96
|
-
<dt>Defined in:</dt>
|
97
|
-
<dd>lib/simple/service/action/indie_hash.rb</dd>
|
98
|
-
</dl>
|
99
|
-
|
100
|
-
</div>
|
101
|
-
|
102
|
-
<h2>Overview</h2><div class="docstring">
|
103
|
-
<div class="discussion">
|
104
|
-
|
105
|
-
<p>The IndieHash class defines as much of the Hash interface as necessary for simple-service to successfully run.</p>
|
106
|
-
|
107
|
-
|
108
|
-
</div>
|
109
|
-
</div>
|
110
|
-
<div class="tags">
|
111
|
-
|
112
|
-
|
113
|
-
</div>
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
<h2>
|
122
|
-
Instance Method Summary
|
123
|
-
<small><a href="#" class="summary_toggle">collapse</a></small>
|
124
|
-
</h2>
|
125
|
-
|
126
|
-
<ul class="summary">
|
127
|
-
|
128
|
-
<li class="public ">
|
129
|
-
<span class="summary_signature">
|
130
|
-
|
131
|
-
<a href="#[]-instance_method" title="#[] (instance method)">#<strong>[]</strong>(sym) ⇒ Object </a>
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
</span>
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
146
|
-
|
147
|
-
</li>
|
148
|
-
|
149
|
-
|
150
|
-
<li class="public ">
|
151
|
-
<span class="summary_signature">
|
152
|
-
|
153
|
-
<a href="#fetch_values-instance_method" title="#fetch_values (instance method)">#<strong>fetch_values</strong>(*keys) ⇒ Object </a>
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
</span>
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
168
|
-
|
169
|
-
</li>
|
170
|
-
|
171
|
-
|
172
|
-
<li class="public ">
|
173
|
-
<span class="summary_signature">
|
174
|
-
|
175
|
-
<a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(hsh) ⇒ IndieHash </a>
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
</span>
|
180
|
-
|
181
|
-
|
182
|
-
<span class="note title constructor">constructor</span>
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
<span class="summary_desc"><div class='inline'>
|
192
|
-
<p>A new instance of IndieHash.</p>
|
193
|
-
</div></span>
|
194
|
-
|
195
|
-
</li>
|
196
|
-
|
197
|
-
|
198
|
-
<li class="public ">
|
199
|
-
<span class="summary_signature">
|
200
|
-
|
201
|
-
<a href="#key%3F-instance_method" title="#key? (instance method)">#<strong>key?</strong>(sym) ⇒ Boolean </a>
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
</span>
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
216
|
-
|
217
|
-
</li>
|
218
|
-
|
219
|
-
|
220
|
-
<li class="public ">
|
221
|
-
<span class="summary_signature">
|
222
|
-
|
223
|
-
<a href="#keys-instance_method" title="#keys (instance method)">#<strong>keys</strong> ⇒ Object </a>
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
</span>
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
238
|
-
|
239
|
-
</li>
|
240
|
-
|
241
|
-
|
242
|
-
<li class="public ">
|
243
|
-
<span class="summary_signature">
|
244
|
-
|
245
|
-
<a href="#merge-instance_method" title="#merge (instance method)">#<strong>merge</strong>(other_hsh) ⇒ Object </a>
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
</span>
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
<span class="summary_desc"><div class='inline'></div></span>
|
260
|
-
|
261
|
-
</li>
|
262
|
-
|
263
|
-
|
264
|
-
</ul>
|
265
|
-
|
266
|
-
|
267
|
-
<div id="constructor_details" class="method_details_list">
|
268
|
-
<h2>Constructor Details</h2>
|
269
|
-
|
270
|
-
<div class="method_details first">
|
271
|
-
<h3 class="signature first" id="initialize-instance_method">
|
272
|
-
|
273
|
-
#<strong>initialize</strong>(hsh) ⇒ <tt><span class='object_link'><a href="" title="Simple::Service::Action::IndieHash (class)">IndieHash</a></span></tt>
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
</h3><div class="docstring">
|
280
|
-
<div class="discussion">
|
281
|
-
|
282
|
-
<p>Returns a new instance of IndieHash</p>
|
283
|
-
|
284
|
-
|
285
|
-
</div>
|
286
|
-
</div>
|
287
|
-
<div class="tags">
|
288
|
-
|
289
|
-
|
290
|
-
</div><table class="source_code">
|
291
|
-
<tr>
|
292
|
-
<td>
|
293
|
-
<pre class="lines">
|
294
|
-
|
295
|
-
|
296
|
-
5
|
297
|
-
6
|
298
|
-
7</pre>
|
299
|
-
</td>
|
300
|
-
<td>
|
301
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 5</span>
|
302
|
-
|
303
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_hsh'>hsh</span><span class='rparen'>)</span>
|
304
|
-
<span class='ivar'>@hsh</span> <span class='op'>=</span> <span class='id identifier rubyid_hsh'>hsh</span><span class='period'>.</span><span class='id identifier rubyid_each_with_object'>each_with_object</span><span class='lparen'>(</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='lparen'>(</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_v'>v</span><span class='rparen'>)</span><span class='comma'>,</span> <span class='id identifier rubyid_h'>h</span><span class='op'>|</span> <span class='id identifier rubyid_h'>h</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_v'>v</span> <span class='rbrace'>}</span>
|
305
|
-
<span class='kw'>end</span></pre>
|
306
|
-
</td>
|
307
|
-
</tr>
|
308
|
-
</table>
|
309
|
-
</div>
|
310
|
-
|
311
|
-
</div>
|
312
|
-
|
313
|
-
|
314
|
-
<div id="instance_method_details" class="method_details_list">
|
315
|
-
<h2>Instance Method Details</h2>
|
316
|
-
|
317
|
-
|
318
|
-
<div class="method_details first">
|
319
|
-
<h3 class="signature first" id="[]-instance_method">
|
320
|
-
|
321
|
-
#<strong>[]</strong>(sym) ⇒ <tt>Object</tt>
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
</h3><table class="source_code">
|
328
|
-
<tr>
|
329
|
-
<td>
|
330
|
-
<pre class="lines">
|
331
|
-
|
332
|
-
|
333
|
-
22
|
334
|
-
23
|
335
|
-
24</pre>
|
336
|
-
</td>
|
337
|
-
<td>
|
338
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 22</span>
|
339
|
-
|
340
|
-
<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_sym'>sym</span><span class='rparen'>)</span>
|
341
|
-
<span class='ivar'>@hsh</span><span class='lbracket'>[</span><span class='id identifier rubyid_sym'>sym</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbracket'>]</span>
|
342
|
-
<span class='kw'>end</span></pre>
|
343
|
-
</td>
|
344
|
-
</tr>
|
345
|
-
</table>
|
346
|
-
</div>
|
347
|
-
|
348
|
-
<div class="method_details ">
|
349
|
-
<h3 class="signature " id="fetch_values-instance_method">
|
350
|
-
|
351
|
-
#<strong>fetch_values</strong>(*keys) ⇒ <tt>Object</tt>
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
</h3><table class="source_code">
|
358
|
-
<tr>
|
359
|
-
<td>
|
360
|
-
<pre class="lines">
|
361
|
-
|
362
|
-
|
363
|
-
13
|
364
|
-
14
|
365
|
-
15
|
366
|
-
16</pre>
|
367
|
-
</td>
|
368
|
-
<td>
|
369
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 13</span>
|
370
|
-
|
371
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_fetch_values'>fetch_values</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span>
|
372
|
-
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='id identifier rubyid_keys'>keys</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lparen'>(</span><span class='op'>&</span><span class='symbol'>:to_s</span><span class='rparen'>)</span>
|
373
|
-
<span class='ivar'>@hsh</span><span class='period'>.</span><span class='id identifier rubyid_fetch_values'>fetch_values</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span>
|
374
|
-
<span class='kw'>end</span></pre>
|
375
|
-
</td>
|
376
|
-
</tr>
|
377
|
-
</table>
|
378
|
-
</div>
|
379
|
-
|
380
|
-
<div class="method_details ">
|
381
|
-
<h3 class="signature " id="key?-instance_method">
|
382
|
-
|
383
|
-
#<strong>key?</strong>(sym) ⇒ <tt>Boolean</tt>
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
</h3><div class="docstring">
|
390
|
-
<div class="discussion">
|
391
|
-
|
392
|
-
|
393
|
-
</div>
|
394
|
-
</div>
|
395
|
-
<div class="tags">
|
396
|
-
|
397
|
-
<p class="tag_title">Returns:</p>
|
398
|
-
<ul class="return">
|
399
|
-
|
400
|
-
<li>
|
401
|
-
|
402
|
-
|
403
|
-
<span class='type'>(<tt>Boolean</tt>)</span>
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
</li>
|
408
|
-
|
409
|
-
</ul>
|
410
|
-
|
411
|
-
</div><table class="source_code">
|
412
|
-
<tr>
|
413
|
-
<td>
|
414
|
-
<pre class="lines">
|
415
|
-
|
416
|
-
|
417
|
-
18
|
418
|
-
19
|
419
|
-
20</pre>
|
420
|
-
</td>
|
421
|
-
<td>
|
422
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 18</span>
|
423
|
-
|
424
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='id identifier rubyid_sym'>sym</span><span class='rparen'>)</span>
|
425
|
-
<span class='ivar'>@hsh</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='id identifier rubyid_sym'>sym</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rparen'>)</span>
|
426
|
-
<span class='kw'>end</span></pre>
|
427
|
-
</td>
|
428
|
-
</tr>
|
429
|
-
</table>
|
430
|
-
</div>
|
431
|
-
|
432
|
-
<div class="method_details ">
|
433
|
-
<h3 class="signature " id="keys-instance_method">
|
434
|
-
|
435
|
-
#<strong>keys</strong> ⇒ <tt>Object</tt>
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
</h3><table class="source_code">
|
442
|
-
<tr>
|
443
|
-
<td>
|
444
|
-
<pre class="lines">
|
445
|
-
|
446
|
-
|
447
|
-
9
|
448
|
-
10
|
449
|
-
11</pre>
|
450
|
-
</td>
|
451
|
-
<td>
|
452
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 9</span>
|
453
|
-
|
454
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_keys'>keys</span>
|
455
|
-
<span class='ivar'>@hsh</span><span class='period'>.</span><span class='id identifier rubyid_keys'>keys</span>
|
456
|
-
<span class='kw'>end</span></pre>
|
457
|
-
</td>
|
458
|
-
</tr>
|
459
|
-
</table>
|
460
|
-
</div>
|
461
|
-
|
462
|
-
<div class="method_details ">
|
463
|
-
<h3 class="signature " id="merge-instance_method">
|
464
|
-
|
465
|
-
#<strong>merge</strong>(other_hsh) ⇒ <tt>Object</tt>
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
</h3><table class="source_code">
|
472
|
-
<tr>
|
473
|
-
<td>
|
474
|
-
<pre class="lines">
|
475
|
-
|
476
|
-
|
477
|
-
26
|
478
|
-
27
|
479
|
-
28
|
480
|
-
29</pre>
|
481
|
-
</td>
|
482
|
-
<td>
|
483
|
-
<pre class="code"><span class="info file"># File 'lib/simple/service/action/indie_hash.rb', line 26</span>
|
484
|
-
|
485
|
-
<span class='kw'>def</span> <span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_other_hsh'>other_hsh</span><span class='rparen'>)</span>
|
486
|
-
<span class='ivar'>@hsh</span> <span class='op'>=</span> <span class='ivar'>@hsh</span><span class='period'>.</span><span class='id identifier rubyid_merge'>merge</span><span class='lparen'>(</span><span class='id identifier rubyid_other_hsh'>other_hsh</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span><span class='symbol'>:__hsh__</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
487
|
-
<span class='kw'>self</span>
|
488
|
-
<span class='kw'>end</span></pre>
|
489
|
-
</td>
|
490
|
-
</tr>
|
491
|
-
</table>
|
492
|
-
</div>
|
493
|
-
|
494
|
-
</div>
|
495
|
-
|
496
|
-
</div>
|
497
|
-
|
498
|
-
<div id="footer">
|
499
|
-
Generated on Tue Dec 3 13:46:26 2019 by
|
500
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
501
|
-
0.9.20 (ruby-2.5.1).
|
502
|
-
</div>
|
503
|
-
|
504
|
-
</div>
|
505
|
-
</body>
|
506
|
-
</html>
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Simple::Service
|
2
|
-
# Returns the current context.
|
3
|
-
def self.context
|
4
|
-
Thread.current[:"Simple::Service.context"]
|
5
|
-
end
|
6
|
-
|
7
|
-
# yields a block with a given context, and restores the previous context
|
8
|
-
# object afterwards.
|
9
|
-
def self.with_context(ctx = nil, &block)
|
10
|
-
old_ctx = Thread.current[:"Simple::Service.context"]
|
11
|
-
new_ctx = old_ctx ? old_ctx.merge(ctx) : Context.new(ctx)
|
12
|
-
|
13
|
-
Thread.current[:"Simple::Service.context"] = new_ctx
|
14
|
-
|
15
|
-
block.call
|
16
|
-
ensure
|
17
|
-
Thread.current[:"Simple::Service.context"] = old_ctx
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module Simple::Service
|
22
|
-
# A context object
|
23
|
-
#
|
24
|
-
# Each service executes with a current context. The system manages a stack of
|
25
|
-
# contexts; whenever a service execution is done the current context is reverted
|
26
|
-
# to its previous value.
|
27
|
-
#
|
28
|
-
# A context object can store a large number of values; the only way to set or
|
29
|
-
# access a value is via getters and setters. These are implemented via
|
30
|
-
# +method_missing(..)+.
|
31
|
-
#
|
32
|
-
# Also, once a value is set in the context it is not possible to change or
|
33
|
-
# unset it.
|
34
|
-
class Context
|
35
|
-
def initialize(hsh = nil) # @private
|
36
|
-
@hsh = hsh || {}
|
37
|
-
end
|
38
|
-
|
39
|
-
# returns a new Context object, which merges the values in the +overlay+
|
40
|
-
# argument (which must be a Hash or nil) with the values in this context.
|
41
|
-
#
|
42
|
-
# The overlay is allowed to change values in the current context.
|
43
|
-
#
|
44
|
-
# It does not change this context.
|
45
|
-
def merge(overlay)
|
46
|
-
expect! overlay => [Hash, nil]
|
47
|
-
|
48
|
-
overlay ||= {}
|
49
|
-
new_context_hsh = @hsh.merge(overlay)
|
50
|
-
::Simple::Service::Context.new(new_context_hsh)
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
IDENTIFIER_PATTERN = "[a-z][a-z0-9_]*" # @private
|
56
|
-
IDENTIFIER_REGEXP = Regexp.compile("\\A#{IDENTIFIER_PATTERN}\\z") # @private
|
57
|
-
ASSIGNMENT_REGEXP = Regexp.compile("\\A(#{IDENTIFIER_PATTERN})=\\z") # @private
|
58
|
-
|
59
|
-
def method_missing(sym, *args, &block)
|
60
|
-
raise ArgumentError, "Block given" if block
|
61
|
-
|
62
|
-
if args.count == 0 && sym =~ IDENTIFIER_REGEXP
|
63
|
-
self[sym]
|
64
|
-
elsif args.count == 1 && sym =~ ASSIGNMENT_REGEXP
|
65
|
-
self[$1.to_sym] = args.first
|
66
|
-
else
|
67
|
-
super
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def respond_to_missing?(sym, include_private = false)
|
72
|
-
# :nocov:
|
73
|
-
return true if IDENTIFIER_REGEXP.match?(sym)
|
74
|
-
return true if ASSIGNMENT_REGEXP.match?(sym)
|
75
|
-
|
76
|
-
super
|
77
|
-
# :nocov:
|
78
|
-
end
|
79
|
-
|
80
|
-
def [](key)
|
81
|
-
@hsh[key]
|
82
|
-
end
|
83
|
-
|
84
|
-
def []=(key, value)
|
85
|
-
existing_value = @hsh[key]
|
86
|
-
|
87
|
-
unless existing_value.nil? || existing_value == value
|
88
|
-
raise ::Simple::Service::ContextReadOnlyError, key
|
89
|
-
end
|
90
|
-
|
91
|
-
@hsh[key] = value
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
@@ -1,69 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Simple::Service do
|
4
|
-
describe ".with_context" do
|
5
|
-
it "merges the current context for the duration of the block" do
|
6
|
-
block_called = false
|
7
|
-
|
8
|
-
Simple::Service.with_context(a: "a") do
|
9
|
-
expect(Simple::Service.context.a).to eq("a")
|
10
|
-
|
11
|
-
# overwrite value
|
12
|
-
Simple::Service.with_context(a: "b") do
|
13
|
-
expect(Simple::Service.context.a).to eq("b")
|
14
|
-
block_called = true
|
15
|
-
end
|
16
|
-
|
17
|
-
# overwrite value w/nil
|
18
|
-
Simple::Service.with_context(a: nil) do
|
19
|
-
expect(Simple::Service.context.a).to be_nil
|
20
|
-
Simple::Service.context.a = "c"
|
21
|
-
expect(Simple::Service.context.a).to eq("c")
|
22
|
-
end
|
23
|
-
expect(Simple::Service.context.a).to eq("a")
|
24
|
-
end
|
25
|
-
|
26
|
-
expect(block_called).to eq(true)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe Simple::Service::Context do
|
32
|
-
let(:context) { Simple::Service::Context.new }
|
33
|
-
|
34
|
-
before do
|
35
|
-
context.one = 1
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "invalid identifier" do
|
39
|
-
it "raises an error" do
|
40
|
-
expect { context.one! }.to raise_error(NoMethodError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "context reading" do
|
45
|
-
it "returns a value if set" do
|
46
|
-
expect(context.one).to eq(1)
|
47
|
-
end
|
48
|
-
|
49
|
-
it "returns nil if not set" do
|
50
|
-
expect(context.two).to be_nil
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "context writing" do
|
55
|
-
it "sets a value if it does not exist yet" do
|
56
|
-
context.two = 2
|
57
|
-
expect(context.two).to eq(2)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "raises a ReadOnly error if the value exists and is not equal" do
|
61
|
-
expect { context.one = 2 }.to raise_error(::Simple::Service::ContextReadOnlyError)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "sets the value if it exists and is equal" do
|
65
|
-
context.one = 1
|
66
|
-
expect(context.one).to eq(1)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|