]> git.r.bdr.sh - rbdr/lyricli.rb/blob - doc/Lyricli/Configuration.html
Merge pull request #2 from orlando/master
[rbdr/lyricli.rb] / doc / Lyricli / Configuration.html
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
9 &mdash; Documentation by YARD 0.8.2.1
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
102 <h2>Overview</h2><div class="docstring">
103 <div class="discussion">
104 <p>
105 This class handles the configuration of Lyricli
106 </p>
107
108
109 </div>
110 </div>
111 <div class="tags">
112
113
114 </div>
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
158 <span class="summary_desc"><div class='inline'><p>
159 Ensure this is only called once.
160 </p>
161 </div></span>
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
178 <a href="#%5B%5D-instance_method" title="#[] (instance method)">- (String, ...) <strong>[]</strong>(key) </a>
179
180
181
182 </span>
183
184
185
186
187
188
189
190
191
192 <span class="summary_desc"><div class='inline'><p>
193 Access configuration properties, loads config if needed beforehand.
194 </p>
195 </div></span>
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
217 <span class="summary_desc"><div class='inline'><p>
218 Assigns a new value to a configuration key, loads config if needed and
219 saves it after updating.
220 </p>
221 </div></span>
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
243 <span class="summary_desc"><div class='inline'><p>
244 Deletes a key from the configuration, loads config if needed and saves it
245 after deleting.
246 </p>
247 </div></span>
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>
272 Defines the paths to the default and user configuration files.
273 </p>
274 </div></span>
275
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>
297 Loads the configuration from the user file, attempts to create it from
298 defaults if it&#8217;s not present.
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
322 <span class="summary_desc"><div class='inline'><p>
323 Serializes the `@config` Hash to JSON and saves it to a file.
324 </p>
325 </div></span>
326
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>
348 Defines the paths to the default and user configuration files
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
363 7
364 8
365 9
366 10
367 11</pre>
368 </td>
369 <td>
370 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 7</span>
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>
375 <span class='ivar'>@config</span> <span class='op'>=</span> <span class='kw'>nil</span>
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
398 </h3><div class="docstring">
399 <div class="discussion">
400 <p>
401 Ensure this is only called once. Only use the instance class variable to
402 access 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">
412 <tr>
413 <td>
414 <pre class="lines">
415
416
417 17
418 18
419 19</pre>
420 </td>
421 <td>
422 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 17</span>
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
441 - (<tt>String</tt>, ...) <strong>[]</strong>(key)
442
443
444
445
446
447 </h3><div class="docstring">
448 <div class="discussion">
449 <p>
450 Access configuration properties, loads config if needed beforehand.
451 </p>
452
453
454 </div>
455 </div>
456 <div class="tags">
457 <p class="tag_title">Parameters:</p>
458 <ul class="param">
459
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>
471 the 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>
491 the value of the configuration key.
492 </p>
493 </div>
494
495 </li>
496
497 </ul>
498
499 </div><table class="source_code">
500 <tr>
501 <td>
502 <pre class="lines">
503
504
505 25
506 26
507 27
508 28</pre>
509 </td>
510 <td>
511 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 25</span>
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
531 </h3><div class="docstring">
532 <div class="discussion">
533 <p>
534 Assigns a new value to a configuration key, loads config if needed and
535 saves 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>
556 the 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>
573 the value for the configuration key, can be any object as long as it can be
574 converted to JSON
575 </p>
576 </div>
577
578 </li>
579
580 </ul>
581
582
583 </div><table class="source_code">
584 <tr>
585 <td>
586 <pre class="lines">
587
588
589 36
590 37
591 38
592 39
593 40</pre>
594 </td>
595 <td>
596 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 36</span>
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>
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
617 </h3><div class="docstring">
618 <div class="discussion">
619 <p>
620 Deletes a key from the configuration, loads config if needed and saves it
621 after 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>
642 the key to delete
643 </p>
644 </div>
645
646 </li>
647
648 </ul>
649
650
651 </div><table class="source_code">
652 <tr>
653 <td>
654 <pre class="lines">
655
656
657 46
658 47
659 48
660 49
661 50</pre>
662 </td>
663 <td>
664 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 46</span>
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>
688 Loads the configuration from the user file, attempts to create it from
689 defaults if it&#8217;s not present. sets the `@config` instance variable.
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
704 56
705 57
706 58
707 59
708 60
709 61
710 62
711 63
712 64
713 65</pre>
714 </td>
715 <td>
716 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 56</span>
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
742 </h3><div class="docstring">
743 <div class="discussion">
744 <p>
745 Serializes 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">
755 <tr>
756 <td>
757 <pre class="lines">
758
759
760 68
761 69
762 70
763 71
764 72
765 73</pre>
766 </td>
767 <td>
768 <pre class="code"><span class="info file"># File 'lib/lyricli/configuration.rb', line 68</span>
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>
779 </div>
780
781 </div>
782
783 </div>
784
785 <div id="footer">
786 Generated on Sat Oct 6 03:20:24 2012 by
787 <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
788 0.8.2.1 (ruby-1.9.2).
789 </div>
790
791 </body>
792 </html>