]> git.r.bdr.sh - rbdr/lyricli.rb/blame - doc/Lyricli/Configuration.html
Quick Update to the readme
[rbdr/lyricli.rb] / doc / Lyricli / Configuration.html
CommitLineData
823e558b
BB
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 Class: Lyricli::Configuration
8
34d0bf15 9 &mdash; Documentation by YARD 0.8.2.1
823e558b
BB
10
11</title>
12
13 <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
14
15 <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" 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="../Lyricli.html" title="Lyricli (module)">Lyricli</a></span></span>
36 &raquo;
37 <span class="title">Configuration</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>Class: Lyricli::Configuration
67
68
69
70</h1>
71
72<dl class="box">
73
74 <dt class="r1">Inherits:</dt>
75 <dd class="r1">
76 <span class="inheritName">Object</span>
77
78 <ul class="fullTree">
79 <li>Object</li>
80
81 <li class="next">Lyricli::Configuration</li>
82
83 </ul>
84 <a href="#" class="inheritanceTree">show all</a>
85
86 </dd>
87
88
89
90
91
92
93
94
95
96 <dt class="r2 last">Defined in:</dt>
97 <dd class="r2 last">lib/lyricli/configuration.rb</dd>
98
99</dl>
100<div class="clear"></div>
101
f2ec7254
BB
102<h2>Overview</h2><div class="docstring">
103 <div class="discussion">
104 <p>
105This class handles the configuration of Lyricli
106</p>
107
108
109 </div>
110</div>
111<div class="tags">
112
823e558b 113
f2ec7254 114</div>
823e558b
BB
115 <h2>Constant Summary</h2>
116
117 <dl class="constants">
118
119 <dt id="instance-classvariable" class="">@@instance =
120
121 </dt>
122 <dd><pre class="code"><span class='const'>Configuration</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span></pre></dd>
123
124 </dl>
125
126
127
128
129
130
131
132
133
134 <h2>
135 Class Method Summary
136 <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
137 </h2>
138
139 <ul class="summary">
140
141 <li class="public ">
142 <span class="summary_signature">
143
144 <a href="#instance-class_method" title="instance (class method)">+ (Object) <strong>instance</strong> </a>
145
146
147
148 </span>
149
150
151
152
153
154
155
156
157
f2ec7254
BB
158 <span class="summary_desc"><div class='inline'><p>
159Ensure this is only called once.
160</p>
161</div></span>
823e558b
BB
162
163</li>
164
165
166 </ul>
167
168 <h2>
169 Instance Method Summary
170 <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
171 </h2>
172
173 <ul class="summary">
174
175 <li class="public ">
176 <span class="summary_signature">
177
f2ec7254 178 <a href="#%5B%5D-instance_method" title="#[] (instance method)">- (String, ...) <strong>[]</strong>(key) </a>
823e558b
BB
179
180
181
182 </span>
183
184
185
186
187
188
189
190
191
f2ec7254
BB
192 <span class="summary_desc"><div class='inline'><p>
193Access configuration properties, loads config if needed beforehand.
194</p>
195</div></span>
823e558b
BB
196
197</li>
198
199
200 <li class="public ">
201 <span class="summary_signature">
202
203 <a href="#%5B%5D%3D-instance_method" title="#[]= (instance method)">- (Object) <strong>[]=</strong>(key, value) </a>
204
205
206
207 </span>
208
209
210
211
212
213
214
215
216
f2ec7254
BB
217 <span class="summary_desc"><div class='inline'><p>
218Assigns a new value to a configuration key, loads config if needed and
219saves it after updating.
220</p>
221</div></span>
34d0bf15
BB
222
223</li>
224
225
226 <li class="public ">
227 <span class="summary_signature">
228
229 <a href="#delete-instance_method" title="#delete (instance method)">- (Object) <strong>delete</strong>(key) </a>
230
231
232
233 </span>
234
235
236
237
238
239
240
241
242
f2ec7254
BB
243 <span class="summary_desc"><div class='inline'><p>
244Deletes a key from the configuration, loads config if needed and saves it
245after deleting.
246</p>
247</div></span>
823e558b
BB
248
249</li>
250
251
252 <li class="public ">
253 <span class="summary_signature">
254
255 <a href="#initialize-instance_method" title="#initialize (instance method)">- (Configuration) <strong>initialize</strong> </a>
256
257
258
259 </span>
260
261
262 <span class="note title constructor">constructor</span>
263
264
265
266
267
268
269
270
271 <span class="summary_desc"><div class='inline'><p>
f2ec7254 272Defines the paths to the default and user configuration files.
823e558b
BB
273</p>
274</div></span>
275
34d0bf15
BB
276</li>
277
278
279 <li class="public ">
280 <span class="summary_signature">
281
282 <a href="#load_config-instance_method" title="#load_config (instance method)">- (Object) <strong>load_config</strong> </a>
283
284
285
286 </span>
287
288
289
290
291
292
293
294
295
296 <span class="summary_desc"><div class='inline'><p>
f2ec7254
BB
297Loads the configuration from the user file, attempts to create it from
298defaults if it&#8217;s not present.
34d0bf15
BB
299</p>
300</div></span>
301
302</li>
303
304
305 <li class="public ">
306 <span class="summary_signature">
307
308 <a href="#save_config-instance_method" title="#save_config (instance method)">- (Object) <strong>save_config</strong> </a>
309
310
311
312 </span>
313
314
315
316
317
318
319
320
321
f2ec7254
BB
322 <span class="summary_desc"><div class='inline'><p>
323Serializes the `@config` Hash to JSON and saves it to a file.
324</p>
325</div></span>
34d0bf15 326
823e558b
BB
327</li>
328
329
330 </ul>
331
332
333<div id="constructor_details" class="method_details_list">
334 <h2>Constructor Details</h2>
335
336 <div class="method_details first">
337 <h3 class="signature first" id="initialize-instance_method">
338
339 - (<tt><span class='object_link'><a href="" title="Lyricli::Configuration (class)">Configuration</a></span></tt>) <strong>initialize</strong>
340
341
342
343
344
345</h3><div class="docstring">
346 <div class="discussion">
347 <p>
f2ec7254 348Defines the paths to the default and user configuration files
823e558b
BB
349</p>
350
351
352 </div>
353</div>
354<div class="tags">
355
356
357</div><table class="source_code">
358 <tr>
359 <td>
360 <pre class="lines">
361
362
34d0bf15 3637
f2ec7254
BB
3648
3659
36610
36711</pre>
823e558b
BB
368 </td>
369 <td>
f2ec7254 370 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 7</span>
823e558b
BB
371
372<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
373 <span class='ivar'>@config_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>~/.lyricli.conf</span><span class='tstring_end'>&quot;</span></span>
374 <span class='ivar'>@defaults_path</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>defaults.json</span><span class='tstring_end'>&quot;</span></span>
34d0bf15 375 <span class='ivar'>@config</span> <span class='op'>=</span> <span class='kw'>nil</span>
823e558b
BB
376<span class='kw'>end</span></pre>
377 </td>
378 </tr>
379</table>
380</div>
381
382</div>
383
384
385 <div id="class_method_details" class="method_details_list">
386 <h2>Class Method Details</h2>
387
388
389 <div class="method_details first">
390 <h3 class="signature first" id="instance-class_method">
391
392 + (<tt>Object</tt>) <strong>instance</strong>
393
394
395
396
397
f2ec7254
BB
398</h3><div class="docstring">
399 <div class="discussion">
400 <p>
401Ensure this is only called once. Only use the instance class variable to
402access this method, as its constructor is private.
403</p>
404
405
406 </div>
407</div>
408<div class="tags">
409
410
411</div><table class="source_code">
823e558b
BB
412 <tr>
413 <td>
414 <pre class="lines">
415
416
f2ec7254
BB
41717
41818
41919</pre>
823e558b
BB
420 </td>
421 <td>
f2ec7254 422 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 17</span>
823e558b
BB
423
424<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_instance'>instance</span>
425 <span class='cvar'>@@instance</span>
426<span class='kw'>end</span></pre>
427 </td>
428 </tr>
429</table>
430</div>
431
432 </div>
433
434 <div id="instance_method_details" class="method_details_list">
435 <h2>Instance Method Details</h2>
436
437
438 <div class="method_details first">
439 <h3 class="signature first" id="[]-instance_method">
440
f2ec7254
BB
441 - (<tt>String</tt>, ...) <strong>[]</strong>(key)
442
443
823e558b
BB
444
445
446
f2ec7254
BB
447</h3><div class="docstring">
448 <div class="discussion">
449 <p>
450Access configuration properties, loads config if needed beforehand.
451</p>
452
823e558b 453
f2ec7254
BB
454 </div>
455</div>
456<div class="tags">
457 <p class="tag_title">Parameters:</p>
458<ul class="param">
823e558b 459
f2ec7254
BB
460 <li>
461
462 <span class='name'>key</span>
463
464
465 <span class='type'>(<tt>String</tt>)</span>
466
467
468
469 &mdash;
470 <div class='inline'><p>
471the configuration key to access
472</p>
473</div>
474
475 </li>
476
477</ul>
478
479<p class="tag_title">Returns:</p>
480<ul class="return">
481
482 <li>
483
484
485 <span class='type'>(<tt>String</tt>, <tt>Hash</tt>, <tt>Array</tt>)</span>
486
487
488
489 &mdash;
490 <div class='inline'><p>
491the value of the configuration key.
492</p>
493</div>
494
495 </li>
496
497</ul>
498
499</div><table class="source_code">
823e558b
BB
500 <tr>
501 <td>
502 <pre class="lines">
503
504
f2ec7254
BB
50525
50626
50727
50828</pre>
823e558b
BB
509 </td>
510 <td>
f2ec7254 511 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 25</span>
823e558b
BB
512
513<span class='kw'>def</span> <span class='op'>[]</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
514 <span class='id identifier rubyid_load_config'>load_config</span> <span class='kw'>unless</span> <span class='ivar'>@config</span>
515 <span class='ivar'>@config</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span>
516<span class='kw'>end</span></pre>
517 </td>
518 </tr>
519</table>
520</div>
521
522 <div class="method_details ">
523 <h3 class="signature " id="[]=-instance_method">
524
525 - (<tt>Object</tt>) <strong>[]=</strong>(key, value)
526
527
528
529
530
f2ec7254
BB
531</h3><div class="docstring">
532 <div class="discussion">
533 <p>
534Assigns a new value to a configuration key, loads config if needed and
535saves it after updating.
536</p>
537
538
539 </div>
540</div>
541<div class="tags">
542 <p class="tag_title">Parameters:</p>
543<ul class="param">
544
545 <li>
546
547 <span class='name'>key</span>
548
549
550 <span class='type'>(<tt>String</tt>)</span>
551
552
553
554 &mdash;
555 <div class='inline'><p>
556the configuration key to set
557</p>
558</div>
559
560 </li>
561
562 <li>
563
564 <span class='name'>value</span>
565
566
567 <span class='type'>(<tt>Object</tt>)</span>
568
569
570
571 &mdash;
572 <div class='inline'><p>
573the value for the configuration key, can be any object as long as it can be
574converted to JSON
575</p>
576</div>
577
578 </li>
579
580</ul>
581
582
583</div><table class="source_code">
823e558b
BB
584 <tr>
585 <td>
586 <pre class="lines">
587
588
f2ec7254
BB
58936
59037
59138
59239
59340</pre>
823e558b
BB
594 </td>
595 <td>
f2ec7254 596 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 36</span>
823e558b
BB
597
598<span class='kw'>def</span> <span class='op'>[]=</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span> <span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span>
599 <span class='id identifier rubyid_load_config'>load_config</span> <span class='kw'>unless</span> <span class='ivar'>@config</span>
600 <span class='ivar'>@config</span><span class='lbracket'>[</span><span class='id identifier rubyid_key'>key</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_value'>value</span>
601 <span class='id identifier rubyid_save_config'>save_config</span>
602<span class='kw'>end</span></pre>
603 </td>
604 </tr>
605</table>
34d0bf15
BB
606</div>
607
608 <div class="method_details ">
609 <h3 class="signature " id="delete-instance_method">
610
611 - (<tt>Object</tt>) <strong>delete</strong>(key)
612
613
614
615
616
f2ec7254
BB
617</h3><div class="docstring">
618 <div class="discussion">
619 <p>
620Deletes a key from the configuration, loads config if needed and saves it
621after deleting.
622</p>
623
624
625 </div>
626</div>
627<div class="tags">
628 <p class="tag_title">Parameters:</p>
629<ul class="param">
630
631 <li>
632
633 <span class='name'>key</span>
634
635
636 <span class='type'>(<tt>String</tt>)</span>
637
638
639
640 &mdash;
641 <div class='inline'><p>
642the key to delete
643</p>
644</div>
645
646 </li>
647
648</ul>
649
650
651</div><table class="source_code">
34d0bf15
BB
652 <tr>
653 <td>
654 <pre class="lines">
655
656
f2ec7254
BB
65746
65847
65948
66049
66150</pre>
34d0bf15
BB
662 </td>
663 <td>
f2ec7254 664 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 46</span>
34d0bf15
BB
665
666<span class='kw'>def</span> <span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
667 <span class='id identifier rubyid_load_config'>load_config</span> <span class='kw'>unless</span> <span class='ivar'>@config</span>
668 <span class='ivar'>@config</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='id identifier rubyid_key'>key</span><span class='rparen'>)</span>
669 <span class='id identifier rubyid_save_config'>save_config</span>
670<span class='kw'>end</span></pre>
671 </td>
672 </tr>
673</table>
674</div>
675
676 <div class="method_details ">
677 <h3 class="signature " id="load_config-instance_method">
678
679 - (<tt>Object</tt>) <strong>load_config</strong>
680
681
682
683
684
685</h3><div class="docstring">
686 <div class="discussion">
687 <p>
f2ec7254
BB
688Loads the configuration from the user file, attempts to create it from
689defaults if it&#8217;s not present. sets the `@config` instance variable.
34d0bf15
BB
690</p>
691
692
693 </div>
694</div>
695<div class="tags">
696
697
698</div><table class="source_code">
699 <tr>
700 <td>
701 <pre class="lines">
702
703
f2ec7254
BB
70456
70557
70658
70759
70860
70961
71062
71163
71264
71365</pre>
34d0bf15
BB
714 </td>
715 <td>
f2ec7254 716 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 56</span>
34d0bf15
BB
717
718<span class='kw'>def</span> <span class='id identifier rubyid_load_config'>load_config</span>
719 <span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_expand_path'>expand_path</span><span class='lparen'>(</span><span class='ivar'>@config_path</span><span class='rparen'>)</span>
720
721 <span class='kw'>if</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_exists?'>exists?</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
722 <span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>r</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
723 <span class='ivar'>@config</span> <span class='op'>=</span> <span class='const'>MultiJson</span><span class='period'>.</span><span class='id identifier rubyid_decode'>decode</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='rparen'>)</span>
724 <span class='kw'>else</span>
725 <span class='id identifier rubyid_load_default_config'>load_default_config</span>
726 <span class='kw'>end</span>
727<span class='kw'>end</span></pre>
728 </td>
729 </tr>
730</table>
731</div>
732
733 <div class="method_details ">
734 <h3 class="signature " id="save_config-instance_method">
735
736 - (<tt>Object</tt>) <strong>save_config</strong>
737
738
739
740
741
f2ec7254
BB
742</h3><div class="docstring">
743 <div class="discussion">
744 <p>
745Serializes the `@config` Hash to JSON and saves it to a file.
746</p>
747
748
749 </div>
750</div>
751<div class="tags">
752
753
754</div><table class="source_code">
34d0bf15
BB
755 <tr>
756 <td>
757 <pre class="lines">
758
759
f2ec7254
BB
76068
76169
76270
76371
76472
76573</pre>
34d0bf15
BB
766 </td>
767 <td>
f2ec7254 768 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 68</span>
34d0bf15
BB
769
770<span class='kw'>def</span> <span class='id identifier rubyid_save_config'>save_config</span>
771 <span class='id identifier rubyid_path'>path</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_expand_path'>expand_path</span><span class='lparen'>(</span><span class='ivar'>@config_path</span><span class='rparen'>)</span>
772 <span class='id identifier rubyid_file'>file</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>w</span><span class='tstring_end'>&quot;</span></span><span class='rparen'>)</span>
773 <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_print'>print</span><span class='lparen'>(</span><span class='const'>MultiJson</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='ivar'>@config</span><span class='rparen'>)</span><span class='rparen'>)</span>
774 <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_close'>close</span>
775<span class='kw'>end</span></pre>
776 </td>
777 </tr>
778</table>
823e558b
BB
779</div>
780
781 </div>
782
783</div>
784
785 <div id="footer">
278e6d0a 786 Generated on Sat Oct 6 03:20:24 2012 by
823e558b 787 <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
34d0bf15 788 0.8.2.1 (ruby-1.9.2).
823e558b
BB
789</div>
790
791 </body>
792</html>