triglav-agent 1.0.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +59 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docs/Triglav/Agent/ApiClient/AuthenticationError.html +150 -0
- data/docs/Triglav/Agent/ApiClient/ConnectionError.html +150 -0
- data/docs/Triglav/Agent/ApiClient/Error.html +296 -0
- data/docs/Triglav/Agent/ApiClient.html +545 -0
- data/docs/Triglav/Agent/Base/CLI.html +498 -0
- data/docs/Triglav/Agent/Base/Connection.html +258 -0
- data/docs/Triglav/Agent/Base/Monitor.html +370 -0
- data/docs/Triglav/Agent/Base/Processor.html +623 -0
- data/docs/Triglav/Agent/Base/Setting.html +1081 -0
- data/docs/Triglav/Agent/Base/Worker.html +635 -0
- data/docs/Triglav/Agent/Base.html +121 -0
- data/docs/Triglav/Agent/Configuration.html +967 -0
- data/docs/Triglav/Agent/Error.html +130 -0
- data/docs/Triglav/Agent/HashUtil.html +351 -0
- data/docs/Triglav/Agent/LogFormatter.html +271 -0
- data/docs/Triglav/Agent/Logger.html +287 -0
- data/docs/Triglav/Agent/StorageFile.html +1130 -0
- data/docs/Triglav/Agent/Timer.html +424 -0
- data/docs/Triglav/Agent/TooManyError.html +134 -0
- data/docs/Triglav/Agent.html +131 -0
- data/docs/Triglav.html +119 -0
- data/docs/_index.html +335 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +481 -0
- data/docs/file.LICENSE.html +72 -0
- data/docs/file.README.html +137 -0
- data/docs/file_list.html +61 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +137 -0
- data/docs/js/app.js +243 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +659 -0
- data/docs/top-level-namespace.html +112 -0
- data/example/config.yml +40 -0
- data/lib/triglav/agent/api_client.rb +199 -0
- data/lib/triglav/agent/base/cli.rb +98 -0
- data/lib/triglav/agent/base/connection.rb +30 -0
- data/lib/triglav/agent/base/monitor.rb +32 -0
- data/lib/triglav/agent/base/processor.rb +136 -0
- data/lib/triglav/agent/base/setting.rb +112 -0
- data/lib/triglav/agent/base/worker.rb +95 -0
- data/lib/triglav/agent/configuration.rb +79 -0
- data/lib/triglav/agent/error.rb +4 -0
- data/lib/triglav/agent/hash_util.rb +36 -0
- data/lib/triglav/agent/logger.rb +50 -0
- data/lib/triglav/agent/storage_file.rb +144 -0
- data/lib/triglav/agent/timer.rb +80 -0
- data/lib/triglav/agent/version.rb +5 -0
- data/lib/triglav/agent.rb +20 -0
- data/lib/triglav-agent.rb +1 -0
- data/triglav-agent.gemspec +33 -0
- metadata +250 -0
@@ -0,0 +1,1130 @@
|
|
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: Triglav::Agent::StorageFile
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.5
|
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 = "Triglav::Agent::StorageFile";
|
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"></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 (S)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../../Triglav.html" title="Triglav (module)">Triglav</a></span></span> » <span class='title'><span class='object_link'><a href="../Agent.html" title="Triglav::Agent (module)">Agent</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">StorageFile</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
|
+
<iframe id="search_frame" src="../../class_list.html"></iframe>
|
63
|
+
|
64
|
+
<div id="content"><h1>Class: Triglav::Agent::StorageFile
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
</h1>
|
69
|
+
<div class="box_info">
|
70
|
+
|
71
|
+
<dl>
|
72
|
+
<dt>Inherits:</dt>
|
73
|
+
<dd>
|
74
|
+
<span class="inheritName">Object</span>
|
75
|
+
|
76
|
+
<ul class="fullTree">
|
77
|
+
<li>Object</li>
|
78
|
+
|
79
|
+
<li class="next">Triglav::Agent::StorageFile</li>
|
80
|
+
|
81
|
+
</ul>
|
82
|
+
<a href="#" class="inheritanceTree">show all</a>
|
83
|
+
|
84
|
+
</dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<dl>
|
98
|
+
<dt>Defined in:</dt>
|
99
|
+
<dd>lib/triglav/agent/storage_file.rb</dd>
|
100
|
+
</dl>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
<h2>Overview</h2><div class="docstring">
|
105
|
+
<div class="discussion">
|
106
|
+
|
107
|
+
<p>Thread and inter-process safe YAML file storage</p>
|
108
|
+
|
109
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span>
|
110
|
+
<span class='id identifier rubyid_status'>status</span> <span class='op'>=</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span>
|
111
|
+
<span class='id identifier rubyid_status'>status</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span>
|
112
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_status'>status</span><span class='rparen'>)</span>
|
113
|
+
<span class='kw'>end</span>
|
114
|
+
</code></pre>
|
115
|
+
|
116
|
+
|
117
|
+
</div>
|
118
|
+
</div>
|
119
|
+
<div class="tags">
|
120
|
+
|
121
|
+
|
122
|
+
</div>
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
<h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2>
|
127
|
+
<ul class="summary">
|
128
|
+
|
129
|
+
<li class="public ">
|
130
|
+
<span class="summary_signature">
|
131
|
+
|
132
|
+
<a href="#fp-instance_method" title="#fp (instance method)">#<strong>fp</strong> ⇒ Object </a>
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
</span>
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
<span class="note title readonly">readonly</span>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
<span class="summary_desc"><div class='inline'>
|
152
|
+
<p>Returns the value of attribute fp.</p>
|
153
|
+
</div></span>
|
154
|
+
|
155
|
+
</li>
|
156
|
+
|
157
|
+
|
158
|
+
</ul>
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
<h2>
|
165
|
+
Class Method Summary
|
166
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
167
|
+
</h2>
|
168
|
+
|
169
|
+
<ul class="summary">
|
170
|
+
|
171
|
+
<li class="public ">
|
172
|
+
<span class="summary_signature">
|
173
|
+
|
174
|
+
<a href="#get-class_method" title="get (class method)">.<strong>get</strong>(path, key) ⇒ Object </a>
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
</span>
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
<span class="summary_desc"><div class='inline'>
|
189
|
+
<p>Get value of the given key from storage file.</p>
|
190
|
+
</div></span>
|
191
|
+
|
192
|
+
</li>
|
193
|
+
|
194
|
+
|
195
|
+
<li class="public ">
|
196
|
+
<span class="summary_signature">
|
197
|
+
|
198
|
+
<a href="#getsetnx-class_method" title="getsetnx (class method)">.<strong>getsetnx</strong>(path, key, val) ⇒ Object </a>
|
199
|
+
|
200
|
+
|
201
|
+
|
202
|
+
</span>
|
203
|
+
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
<span class="summary_desc"><div class='inline'>
|
213
|
+
<p>Set key to hold val if key does not exist and returns the holded value.</p>
|
214
|
+
</div></span>
|
215
|
+
|
216
|
+
</li>
|
217
|
+
|
218
|
+
|
219
|
+
<li class="public ">
|
220
|
+
<span class="summary_signature">
|
221
|
+
|
222
|
+
<a href="#load-class_method" title="load (class method)">.<strong>load</strong>(path) ⇒ Hash </a>
|
223
|
+
|
224
|
+
|
225
|
+
|
226
|
+
</span>
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
<span class="summary_desc"><div class='inline'>
|
237
|
+
<p>Load storage file.</p>
|
238
|
+
</div></span>
|
239
|
+
|
240
|
+
</li>
|
241
|
+
|
242
|
+
|
243
|
+
<li class="public ">
|
244
|
+
<span class="summary_signature">
|
245
|
+
|
246
|
+
<a href="#open-class_method" title="open (class method)">.<strong>open</strong>(path, &block) ⇒ Object </a>
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
</span>
|
251
|
+
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
260
|
+
<span class="summary_desc"><div class='inline'>
|
261
|
+
<p>Open storage file.</p>
|
262
|
+
</div></span>
|
263
|
+
|
264
|
+
</li>
|
265
|
+
|
266
|
+
|
267
|
+
<li class="public ">
|
268
|
+
<span class="summary_signature">
|
269
|
+
|
270
|
+
<a href="#set-class_method" title="set (class method)">.<strong>set</strong>(path, key, val) ⇒ Object </a>
|
271
|
+
|
272
|
+
|
273
|
+
|
274
|
+
</span>
|
275
|
+
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
|
284
|
+
<span class="summary_desc"><div class='inline'>
|
285
|
+
<p>Set storage file with given key, value.</p>
|
286
|
+
</div></span>
|
287
|
+
|
288
|
+
</li>
|
289
|
+
|
290
|
+
|
291
|
+
<li class="public ">
|
292
|
+
<span class="summary_signature">
|
293
|
+
|
294
|
+
<a href="#setnx-class_method" title="setnx (class method)">.<strong>setnx</strong>(path, key, val) ⇒ Boolean </a>
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
</span>
|
299
|
+
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
<span class="summary_desc"><div class='inline'>
|
309
|
+
<p>Set key to hold val if key does not exist.</p>
|
310
|
+
</div></span>
|
311
|
+
|
312
|
+
</li>
|
313
|
+
|
314
|
+
|
315
|
+
</ul>
|
316
|
+
|
317
|
+
<h2>
|
318
|
+
Instance Method Summary
|
319
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
320
|
+
</h2>
|
321
|
+
|
322
|
+
<ul class="summary">
|
323
|
+
|
324
|
+
<li class="public ">
|
325
|
+
<span class="summary_signature">
|
326
|
+
|
327
|
+
<a href="#dump-instance_method" title="#dump (instance method)">#<strong>dump</strong>(hash) ⇒ Object </a>
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
</span>
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<span class="summary_desc"><div class='inline'>
|
342
|
+
<p>Dump to storage file.</p>
|
343
|
+
</div></span>
|
344
|
+
|
345
|
+
</li>
|
346
|
+
|
347
|
+
|
348
|
+
<li class="public ">
|
349
|
+
<span class="summary_signature">
|
350
|
+
|
351
|
+
<a href="#load-instance_method" title="#load (instance method)">#<strong>load</strong> ⇒ Hash </a>
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
</span>
|
356
|
+
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
<span class="summary_desc"><div class='inline'>
|
366
|
+
<p>Load storage file.</p>
|
367
|
+
</div></span>
|
368
|
+
|
369
|
+
</li>
|
370
|
+
|
371
|
+
|
372
|
+
</ul>
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
<div id="instance_attr_details" class="attr_details">
|
377
|
+
<h2>Instance Attribute Details</h2>
|
378
|
+
|
379
|
+
|
380
|
+
<span id=""></span>
|
381
|
+
<div class="method_details first">
|
382
|
+
<h3 class="signature first" id="fp-instance_method">
|
383
|
+
|
384
|
+
#<strong>fp</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span>
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
|
390
|
+
</h3><div class="docstring">
|
391
|
+
<div class="discussion">
|
392
|
+
|
393
|
+
<p>Returns the value of attribute fp</p>
|
394
|
+
|
395
|
+
|
396
|
+
</div>
|
397
|
+
</div>
|
398
|
+
<div class="tags">
|
399
|
+
|
400
|
+
|
401
|
+
</div><table class="source_code">
|
402
|
+
<tr>
|
403
|
+
<td>
|
404
|
+
<pre class="lines">
|
405
|
+
|
406
|
+
|
407
|
+
13
|
408
|
+
14
|
409
|
+
15</pre>
|
410
|
+
</td>
|
411
|
+
<td>
|
412
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 13</span>
|
413
|
+
|
414
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_fp'>fp</span>
|
415
|
+
<span class='ivar'>@fp</span>
|
416
|
+
<span class='kw'>end</span></pre>
|
417
|
+
</td>
|
418
|
+
</tr>
|
419
|
+
</table>
|
420
|
+
</div>
|
421
|
+
|
422
|
+
</div>
|
423
|
+
|
424
|
+
|
425
|
+
<div id="class_method_details" class="method_details_list">
|
426
|
+
<h2>Class Method Details</h2>
|
427
|
+
|
428
|
+
|
429
|
+
<div class="method_details first">
|
430
|
+
<h3 class="signature first" id="get-class_method">
|
431
|
+
|
432
|
+
.<strong>get</strong>(path, key) ⇒ <tt>Object</tt>
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
|
437
|
+
|
438
|
+
</h3><div class="docstring">
|
439
|
+
<div class="discussion">
|
440
|
+
|
441
|
+
<p>Get value of the given key from storage file</p>
|
442
|
+
|
443
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># like h['foo'] = 'bar'
|
444
|
+
</span><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>a</span><span class='tstring_end'>'</span></span><span class='comma'>,</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='rparen'>)</span> <span class='comment'># like hash['a']['b']
|
445
|
+
</span></code></pre>
|
446
|
+
|
447
|
+
|
448
|
+
</div>
|
449
|
+
</div>
|
450
|
+
<div class="tags">
|
451
|
+
<p class="tag_title">Parameters:</p>
|
452
|
+
<ul class="param">
|
453
|
+
|
454
|
+
<li>
|
455
|
+
|
456
|
+
<span class='name'>path</span>
|
457
|
+
|
458
|
+
|
459
|
+
<span class='type'>(<tt>String</tt>)</span>
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
</li>
|
464
|
+
|
465
|
+
<li>
|
466
|
+
|
467
|
+
<span class='name'>key</span>
|
468
|
+
|
469
|
+
|
470
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
471
|
+
|
472
|
+
|
473
|
+
|
474
|
+
</li>
|
475
|
+
|
476
|
+
</ul>
|
477
|
+
|
478
|
+
|
479
|
+
</div><table class="source_code">
|
480
|
+
<tr>
|
481
|
+
<td>
|
482
|
+
<pre class="lines">
|
483
|
+
|
484
|
+
|
485
|
+
121
|
486
|
+
122
|
487
|
+
123
|
488
|
+
124</pre>
|
489
|
+
</td>
|
490
|
+
<td>
|
491
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 121</span>
|
492
|
+
|
493
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
494
|
+
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
495
|
+
<span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='period'>.</span><span class='id identifier rubyid_dig'>dig</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
|
496
|
+
<span class='kw'>end</span></pre>
|
497
|
+
</td>
|
498
|
+
</tr>
|
499
|
+
</table>
|
500
|
+
</div>
|
501
|
+
|
502
|
+
<div class="method_details ">
|
503
|
+
<h3 class="signature " id="getsetnx-class_method">
|
504
|
+
|
505
|
+
.<strong>getsetnx</strong>(path, key, val) ⇒ <tt>Object</tt>
|
506
|
+
|
507
|
+
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
</h3><div class="docstring">
|
512
|
+
<div class="discussion">
|
513
|
+
|
514
|
+
<p>Set key to hold val if key does not exist and returns the holded value</p>
|
515
|
+
|
516
|
+
<p>This is a kind of atomic short hand of</p>
|
517
|
+
|
518
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_setnx'>setnx</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
519
|
+
<span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_get'>get</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
520
|
+
</code></pre>
|
521
|
+
|
522
|
+
|
523
|
+
</div>
|
524
|
+
</div>
|
525
|
+
<div class="tags">
|
526
|
+
<p class="tag_title">Parameters:</p>
|
527
|
+
<ul class="param">
|
528
|
+
|
529
|
+
<li>
|
530
|
+
|
531
|
+
<span class='name'>path</span>
|
532
|
+
|
533
|
+
|
534
|
+
<span class='type'>(<tt>String</tt>)</span>
|
535
|
+
|
536
|
+
|
537
|
+
|
538
|
+
</li>
|
539
|
+
|
540
|
+
<li>
|
541
|
+
|
542
|
+
<span class='name'>key</span>
|
543
|
+
|
544
|
+
|
545
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
</li>
|
550
|
+
|
551
|
+
<li>
|
552
|
+
|
553
|
+
<span class='name'>val</span>
|
554
|
+
|
555
|
+
|
556
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
557
|
+
|
558
|
+
|
559
|
+
|
560
|
+
</li>
|
561
|
+
|
562
|
+
</ul>
|
563
|
+
|
564
|
+
<p class="tag_title">Returns:</p>
|
565
|
+
<ul class="return">
|
566
|
+
|
567
|
+
<li>
|
568
|
+
|
569
|
+
|
570
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
571
|
+
|
572
|
+
|
573
|
+
|
574
|
+
—
|
575
|
+
<div class='inline'>
|
576
|
+
<p>holded value</p>
|
577
|
+
</div>
|
578
|
+
|
579
|
+
</li>
|
580
|
+
|
581
|
+
</ul>
|
582
|
+
|
583
|
+
</div><table class="source_code">
|
584
|
+
<tr>
|
585
|
+
<td>
|
586
|
+
<pre class="lines">
|
587
|
+
|
588
|
+
|
589
|
+
101
|
590
|
+
102
|
591
|
+
103
|
592
|
+
104
|
593
|
+
105
|
594
|
+
106
|
595
|
+
107
|
596
|
+
108
|
597
|
+
109
|
598
|
+
110
|
599
|
+
111
|
600
|
+
112</pre>
|
601
|
+
</td>
|
602
|
+
<td>
|
603
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 101</span>
|
604
|
+
|
605
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_getsetnx'>getsetnx</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
606
|
+
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
607
|
+
<span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span>
|
608
|
+
<span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span>
|
609
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_curr'>curr</span> <span class='op'>=</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_dig'>dig</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span>
|
610
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_curr'>curr</span>
|
611
|
+
<span class='kw'>end</span>
|
612
|
+
<span class='const'>HashUtil</span><span class='period'>.</span><span class='id identifier rubyid_setdig'>setdig</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='comma'>,</span> <span class='id identifier rubyid_keys'>keys</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
613
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
|
614
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_val'>val</span>
|
615
|
+
<span class='kw'>end</span>
|
616
|
+
<span class='kw'>end</span></pre>
|
617
|
+
</td>
|
618
|
+
</tr>
|
619
|
+
</table>
|
620
|
+
</div>
|
621
|
+
|
622
|
+
<div class="method_details ">
|
623
|
+
<h3 class="signature " id="load-class_method">
|
624
|
+
|
625
|
+
.<strong>load</strong>(path) ⇒ <tt>Hash</tt>
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
|
630
|
+
|
631
|
+
</h3><div class="docstring">
|
632
|
+
<div class="discussion">
|
633
|
+
|
634
|
+
<p>Load storage file</p>
|
635
|
+
|
636
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='rparen'>)</span>
|
637
|
+
</code></pre>
|
638
|
+
|
639
|
+
|
640
|
+
</div>
|
641
|
+
</div>
|
642
|
+
<div class="tags">
|
643
|
+
<p class="tag_title">Parameters:</p>
|
644
|
+
<ul class="param">
|
645
|
+
|
646
|
+
<li>
|
647
|
+
|
648
|
+
<span class='name'>path</span>
|
649
|
+
|
650
|
+
|
651
|
+
<span class='type'>(<tt>String</tt>)</span>
|
652
|
+
|
653
|
+
|
654
|
+
|
655
|
+
</li>
|
656
|
+
|
657
|
+
</ul>
|
658
|
+
|
659
|
+
<p class="tag_title">Returns:</p>
|
660
|
+
<ul class="return">
|
661
|
+
|
662
|
+
<li>
|
663
|
+
|
664
|
+
|
665
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
666
|
+
|
667
|
+
|
668
|
+
|
669
|
+
</li>
|
670
|
+
|
671
|
+
</ul>
|
672
|
+
|
673
|
+
</div><table class="source_code">
|
674
|
+
<tr>
|
675
|
+
<td>
|
676
|
+
<pre class="lines">
|
677
|
+
|
678
|
+
|
679
|
+
25
|
680
|
+
26
|
681
|
+
27</pre>
|
682
|
+
</td>
|
683
|
+
<td>
|
684
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 25</span>
|
685
|
+
|
686
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
|
687
|
+
<span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span> <span class='rbrace'>}</span>
|
688
|
+
<span class='kw'>end</span></pre>
|
689
|
+
</td>
|
690
|
+
</tr>
|
691
|
+
</table>
|
692
|
+
</div>
|
693
|
+
|
694
|
+
<div class="method_details ">
|
695
|
+
<h3 class="signature " id="open-class_method">
|
696
|
+
|
697
|
+
.<strong>open</strong>(path, &block) ⇒ <tt>Object</tt>
|
698
|
+
|
699
|
+
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
</h3><div class="docstring">
|
704
|
+
<div class="discussion">
|
705
|
+
|
706
|
+
<p>Open storage file</p>
|
707
|
+
|
708
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span>
|
709
|
+
<span class='id identifier rubyid_status'>status</span> <span class='op'>=</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span>
|
710
|
+
<span class='id identifier rubyid_status'>status</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span>
|
711
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_status'>status</span><span class='rparen'>)</span>
|
712
|
+
<span class='kw'>end</span>
|
713
|
+
</code></pre>
|
714
|
+
|
715
|
+
|
716
|
+
</div>
|
717
|
+
</div>
|
718
|
+
<div class="tags">
|
719
|
+
<p class="tag_title">Parameters:</p>
|
720
|
+
<ul class="param">
|
721
|
+
|
722
|
+
<li>
|
723
|
+
|
724
|
+
<span class='name'>path</span>
|
725
|
+
|
726
|
+
|
727
|
+
<span class='type'>(<tt>String</tt>)</span>
|
728
|
+
|
729
|
+
|
730
|
+
|
731
|
+
</li>
|
732
|
+
|
733
|
+
<li>
|
734
|
+
|
735
|
+
<span class='name'>block</span>
|
736
|
+
|
737
|
+
|
738
|
+
<span class='type'>(<tt>Block</tt>)</span>
|
739
|
+
|
740
|
+
|
741
|
+
|
742
|
+
</li>
|
743
|
+
|
744
|
+
</ul>
|
745
|
+
|
746
|
+
|
747
|
+
</div><table class="source_code">
|
748
|
+
<tr>
|
749
|
+
<td>
|
750
|
+
<pre class="lines">
|
751
|
+
|
752
|
+
|
753
|
+
39
|
754
|
+
40
|
755
|
+
41
|
756
|
+
42
|
757
|
+
43
|
758
|
+
44
|
759
|
+
45
|
760
|
+
46
|
761
|
+
47
|
762
|
+
48
|
763
|
+
49
|
764
|
+
50
|
765
|
+
51</pre>
|
766
|
+
</td>
|
767
|
+
<td>
|
768
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 39</span>
|
769
|
+
|
770
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
|
771
|
+
<span class='id identifier rubyid_fp'>fp</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='lparen'>(</span><span class='const'>File</span><span class='op'>::</span><span class='const'>RDONLY</span> <span class='op'>|</span> <span class='const'>File</span><span class='op'>::</span><span class='const'>CREAT</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
772
|
+
<span class='kw'>until</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_flock'>flock</span><span class='lparen'>(</span><span class='const'>File</span><span class='op'>::</span><span class='const'>LOCK_EX</span> <span class='op'>|</span> <span class='const'>File</span><span class='op'>::</span><span class='const'>LOCK_NB</span><span class='rparen'>)</span>
|
773
|
+
<span class='gvar'>$logger</span><span class='period'>.</span><span class='id identifier rubyid_info'>info</span> <span class='lbrace'>{</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Somebody else is locking the storage file </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
|
774
|
+
<span class='id identifier rubyid_sleep'>sleep</span> <span class='float'>0.5</span>
|
775
|
+
<span class='kw'>end</span>
|
776
|
+
<span class='kw'>begin</span>
|
777
|
+
<span class='kw'>return</span> <span class='kw'>yield</span><span class='lparen'>(</span><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_fp'>fp</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
778
|
+
<span class='kw'>ensure</span>
|
779
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_flock'>flock</span><span class='lparen'>(</span><span class='const'>File</span><span class='op'>::</span><span class='const'>LOCK_UN</span><span class='rparen'>)</span>
|
780
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span> <span class='kw'>rescue</span> <span class='kw'>nil</span>
|
781
|
+
<span class='kw'>end</span>
|
782
|
+
<span class='kw'>end</span></pre>
|
783
|
+
</td>
|
784
|
+
</tr>
|
785
|
+
</table>
|
786
|
+
</div>
|
787
|
+
|
788
|
+
<div class="method_details ">
|
789
|
+
<h3 class="signature " id="set-class_method">
|
790
|
+
|
791
|
+
.<strong>set</strong>(path, key, val) ⇒ <tt>Object</tt>
|
792
|
+
|
793
|
+
|
794
|
+
|
795
|
+
|
796
|
+
|
797
|
+
</h3><div class="docstring">
|
798
|
+
<div class="discussion">
|
799
|
+
|
800
|
+
<p>Set storage file with given key, value</p>
|
801
|
+
|
802
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_set'>set</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># like h['foo'] = 'bar'
|
803
|
+
</span><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_set'>set</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>a</span><span class='tstring_end'>'</span></span><span class='comma'>,</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># like h['a']['b'] = 'bar'
|
804
|
+
</span></code></pre>
|
805
|
+
|
806
|
+
|
807
|
+
</div>
|
808
|
+
</div>
|
809
|
+
<div class="tags">
|
810
|
+
<p class="tag_title">Parameters:</p>
|
811
|
+
<ul class="param">
|
812
|
+
|
813
|
+
<li>
|
814
|
+
|
815
|
+
<span class='name'>path</span>
|
816
|
+
|
817
|
+
|
818
|
+
<span class='type'>(<tt>String</tt>)</span>
|
819
|
+
|
820
|
+
|
821
|
+
|
822
|
+
</li>
|
823
|
+
|
824
|
+
<li>
|
825
|
+
|
826
|
+
<span class='name'>key</span>
|
827
|
+
|
828
|
+
|
829
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
830
|
+
|
831
|
+
|
832
|
+
|
833
|
+
</li>
|
834
|
+
|
835
|
+
<li>
|
836
|
+
|
837
|
+
<span class='name'>val</span>
|
838
|
+
|
839
|
+
|
840
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
841
|
+
|
842
|
+
|
843
|
+
|
844
|
+
</li>
|
845
|
+
|
846
|
+
</ul>
|
847
|
+
|
848
|
+
|
849
|
+
</div><table class="source_code">
|
850
|
+
<tr>
|
851
|
+
<td>
|
852
|
+
<pre class="lines">
|
853
|
+
|
854
|
+
|
855
|
+
61
|
856
|
+
62
|
857
|
+
63
|
858
|
+
64
|
859
|
+
65
|
860
|
+
66
|
861
|
+
67
|
862
|
+
68</pre>
|
863
|
+
</td>
|
864
|
+
<td>
|
865
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 61</span>
|
866
|
+
|
867
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_set'>set</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
868
|
+
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
869
|
+
<span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span>
|
870
|
+
<span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span>
|
871
|
+
<span class='const'>HashUtil</span><span class='period'>.</span><span class='id identifier rubyid_setdig'>setdig</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='comma'>,</span> <span class='id identifier rubyid_keys'>keys</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
872
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
|
873
|
+
<span class='kw'>end</span>
|
874
|
+
<span class='kw'>end</span></pre>
|
875
|
+
</td>
|
876
|
+
</tr>
|
877
|
+
</table>
|
878
|
+
</div>
|
879
|
+
|
880
|
+
<div class="method_details ">
|
881
|
+
<h3 class="signature " id="setnx-class_method">
|
882
|
+
|
883
|
+
.<strong>setnx</strong>(path, key, val) ⇒ <tt>Boolean</tt>
|
884
|
+
|
885
|
+
|
886
|
+
|
887
|
+
|
888
|
+
|
889
|
+
</h3><div class="docstring">
|
890
|
+
<div class="discussion">
|
891
|
+
|
892
|
+
<p>Set key to hold val if key does not exist</p>
|
893
|
+
|
894
|
+
<pre class="code ruby"><code class="ruby"><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_setnx'>setnx</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>foo</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># like h['foo'] = 'bar'
|
895
|
+
</span><span class='const'>StorageFile</span><span class='period'>.</span><span class='id identifier rubyid_setnx'>setnx</span><span class='lparen'>(</span><span class='gvar'>$setting</span><span class='period'>.</span><span class='id identifier rubyid_status_file'>status_file</span><span class='comma'>,</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>a</span><span class='tstring_end'>'</span></span><span class='comma'>,</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>b</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>bar</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># like h['a']['b'] = 'bar'
|
896
|
+
</span></code></pre>
|
897
|
+
|
898
|
+
|
899
|
+
</div>
|
900
|
+
</div>
|
901
|
+
<div class="tags">
|
902
|
+
<p class="tag_title">Parameters:</p>
|
903
|
+
<ul class="param">
|
904
|
+
|
905
|
+
<li>
|
906
|
+
|
907
|
+
<span class='name'>path</span>
|
908
|
+
|
909
|
+
|
910
|
+
<span class='type'>(<tt>String</tt>)</span>
|
911
|
+
|
912
|
+
|
913
|
+
|
914
|
+
</li>
|
915
|
+
|
916
|
+
<li>
|
917
|
+
|
918
|
+
<span class='name'>key</span>
|
919
|
+
|
920
|
+
|
921
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
922
|
+
|
923
|
+
|
924
|
+
|
925
|
+
</li>
|
926
|
+
|
927
|
+
<li>
|
928
|
+
|
929
|
+
<span class='name'>val</span>
|
930
|
+
|
931
|
+
|
932
|
+
<span class='type'>(<tt>Object</tt>)</span>
|
933
|
+
|
934
|
+
|
935
|
+
|
936
|
+
</li>
|
937
|
+
|
938
|
+
</ul>
|
939
|
+
|
940
|
+
<p class="tag_title">Returns:</p>
|
941
|
+
<ul class="return">
|
942
|
+
|
943
|
+
<li>
|
944
|
+
|
945
|
+
|
946
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
947
|
+
|
948
|
+
|
949
|
+
|
950
|
+
—
|
951
|
+
<div class='inline'>
|
952
|
+
<p>true if set (not exist), false if not set (exists)</p>
|
953
|
+
</div>
|
954
|
+
|
955
|
+
</li>
|
956
|
+
|
957
|
+
</ul>
|
958
|
+
|
959
|
+
</div><table class="source_code">
|
960
|
+
<tr>
|
961
|
+
<td>
|
962
|
+
<pre class="lines">
|
963
|
+
|
964
|
+
|
965
|
+
79
|
966
|
+
80
|
967
|
+
81
|
968
|
+
82
|
969
|
+
83
|
970
|
+
84
|
971
|
+
85
|
972
|
+
86
|
973
|
+
87
|
974
|
+
88</pre>
|
975
|
+
</td>
|
976
|
+
<td>
|
977
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 79</span>
|
978
|
+
|
979
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_setnx'>setnx</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
980
|
+
<span class='id identifier rubyid_keys'>keys</span> <span class='op'>=</span> <span class='const'>Array</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
|
981
|
+
<span class='id identifier rubyid_open'>open</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_fp'>fp</span><span class='op'>|</span>
|
982
|
+
<span class='id identifier rubyid_params'>params</span> <span class='op'>=</span> <span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span>
|
983
|
+
<span class='kw'>return</span> <span class='kw'>false</span> <span class='kw'>if</span> <span class='id identifier rubyid_params'>params</span><span class='period'>.</span><span class='id identifier rubyid_dig'>dig</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_keys'>keys</span><span class='rparen'>)</span>
|
984
|
+
<span class='const'>HashUtil</span><span class='period'>.</span><span class='id identifier rubyid_setdig'>setdig</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='comma'>,</span> <span class='id identifier rubyid_keys'>keys</span><span class='comma'>,</span> <span class='id identifier rubyid_val'>val</span><span class='rparen'>)</span>
|
985
|
+
<span class='id identifier rubyid_fp'>fp</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
|
986
|
+
<span class='kw'>return</span> <span class='kw'>true</span>
|
987
|
+
<span class='kw'>end</span>
|
988
|
+
<span class='kw'>end</span></pre>
|
989
|
+
</td>
|
990
|
+
</tr>
|
991
|
+
</table>
|
992
|
+
</div>
|
993
|
+
|
994
|
+
</div>
|
995
|
+
|
996
|
+
<div id="instance_method_details" class="method_details_list">
|
997
|
+
<h2>Instance Method Details</h2>
|
998
|
+
|
999
|
+
|
1000
|
+
<div class="method_details first">
|
1001
|
+
<h3 class="signature first" id="dump-instance_method">
|
1002
|
+
|
1003
|
+
#<strong>dump</strong>(hash) ⇒ <tt>Object</tt>
|
1004
|
+
|
1005
|
+
|
1006
|
+
|
1007
|
+
|
1008
|
+
|
1009
|
+
</h3><div class="docstring">
|
1010
|
+
<div class="discussion">
|
1011
|
+
|
1012
|
+
<p>Dump to storage file</p>
|
1013
|
+
|
1014
|
+
|
1015
|
+
</div>
|
1016
|
+
</div>
|
1017
|
+
<div class="tags">
|
1018
|
+
<p class="tag_title">Parameters:</p>
|
1019
|
+
<ul class="param">
|
1020
|
+
|
1021
|
+
<li>
|
1022
|
+
|
1023
|
+
<span class='name'>hash</span>
|
1024
|
+
|
1025
|
+
|
1026
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
1027
|
+
|
1028
|
+
|
1029
|
+
|
1030
|
+
</li>
|
1031
|
+
|
1032
|
+
</ul>
|
1033
|
+
|
1034
|
+
|
1035
|
+
</div><table class="source_code">
|
1036
|
+
<tr>
|
1037
|
+
<td>
|
1038
|
+
<pre class="lines">
|
1039
|
+
|
1040
|
+
|
1041
|
+
140
|
1042
|
+
141
|
1043
|
+
142</pre>
|
1044
|
+
</td>
|
1045
|
+
<td>
|
1046
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 140</span>
|
1047
|
+
|
1048
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span>
|
1049
|
+
<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='ivar'>@fp</span><span class='period'>.</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_hash'>hash</span><span class='rparen'>)</span><span class='rparen'>)</span>
|
1050
|
+
<span class='kw'>end</span></pre>
|
1051
|
+
</td>
|
1052
|
+
</tr>
|
1053
|
+
</table>
|
1054
|
+
</div>
|
1055
|
+
|
1056
|
+
<div class="method_details ">
|
1057
|
+
<h3 class="signature " id="load-instance_method">
|
1058
|
+
|
1059
|
+
#<strong>load</strong> ⇒ <tt>Hash</tt>
|
1060
|
+
|
1061
|
+
|
1062
|
+
|
1063
|
+
|
1064
|
+
|
1065
|
+
</h3><div class="docstring">
|
1066
|
+
<div class="discussion">
|
1067
|
+
|
1068
|
+
<p>Load storage file</p>
|
1069
|
+
|
1070
|
+
|
1071
|
+
</div>
|
1072
|
+
</div>
|
1073
|
+
<div class="tags">
|
1074
|
+
|
1075
|
+
<p class="tag_title">Returns:</p>
|
1076
|
+
<ul class="return">
|
1077
|
+
|
1078
|
+
<li>
|
1079
|
+
|
1080
|
+
|
1081
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
1082
|
+
|
1083
|
+
|
1084
|
+
|
1085
|
+
</li>
|
1086
|
+
|
1087
|
+
</ul>
|
1088
|
+
|
1089
|
+
</div><table class="source_code">
|
1090
|
+
<tr>
|
1091
|
+
<td>
|
1092
|
+
<pre class="lines">
|
1093
|
+
|
1094
|
+
|
1095
|
+
129
|
1096
|
+
130
|
1097
|
+
131
|
1098
|
+
132
|
1099
|
+
133
|
1100
|
+
134
|
1101
|
+
135</pre>
|
1102
|
+
</td>
|
1103
|
+
<td>
|
1104
|
+
<pre class="code"><span class="info file"># File 'lib/triglav/agent/storage_file.rb', line 129</span>
|
1105
|
+
|
1106
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_load'>load</span>
|
1107
|
+
<span class='kw'>if</span> <span class='op'>!</span><span class='lparen'>(</span><span class='id identifier rubyid_content'>content</span> <span class='op'>=</span> <span class='ivar'>@fp</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
|
1108
|
+
<span class='const'>YAML</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_content'>content</span><span class='rparen'>)</span> <span class='comment'># all keys must be symbols
|
1109
|
+
</span> <span class='kw'>else</span>
|
1110
|
+
<span class='lbrace'>{</span><span class='rbrace'>}</span>
|
1111
|
+
<span class='kw'>end</span>
|
1112
|
+
<span class='kw'>end</span></pre>
|
1113
|
+
</td>
|
1114
|
+
</tr>
|
1115
|
+
</table>
|
1116
|
+
</div>
|
1117
|
+
|
1118
|
+
</div>
|
1119
|
+
|
1120
|
+
</div>
|
1121
|
+
|
1122
|
+
<div id="footer">
|
1123
|
+
Generated on Thu Feb 23 23:20:34 2017 by
|
1124
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
1125
|
+
0.9.5 (ruby-2.3.2).
|
1126
|
+
</div>
|
1127
|
+
|
1128
|
+
</div>
|
1129
|
+
</body>
|
1130
|
+
</html>
|