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">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
7 Class: Lyricli::Configuration
9 — Documentation by YARD
0.8.2.1
13 <link rel=
"stylesheet" href=
"../css/style.css" type=
"text/css" media=
"screen" charset=
"utf-8" />
15 <link rel=
"stylesheet" href=
"../css/common.css" type=
"text/css" media=
"screen" charset=
"utf-8" />
17 <script type=
"text/javascript" charset=
"utf-8">
18 hasFrames = window.top.frames.main ? true : false;
20 framesUrl = "../frames.html#!" + escape(window.location.href);
24 <script type=
"text/javascript" charset=
"utf-8" src=
"../js/jquery.js"></script>
26 <script type=
"text/javascript" charset=
"utf-8" src=
"../js/app.js"></script>
34 <a href=
"../_index.html">Index (C)
</a> »
35 <span class='title'
><span class='object_link'
><a href=
"../Lyricli.html" title=
"Lyricli (module)">Lyricli
</a></span></span>
37 <span class=
"title">Configuration
</span>
40 <div class=
"noframes"><span class=
"title">(
</span><a href=
"." target=
"_top">no frames
</a><span class=
"title">)
</span></div>
45 <a class=
"full_list_link" id=
"class_list_link"
46 href=
"../class_list.html">
50 <a class=
"full_list_link" id=
"method_list_link"
51 href=
"../method_list.html">
55 <a class=
"full_list_link" id=
"file_list_link"
56 href=
"../file_list.html">
61 <div class=
"clear"></div>
64 <iframe id=
"search_frame"></iframe>
66 <div id=
"content"><h1>Class: Lyricli::Configuration
74 <dt class=
"r1">Inherits:
</dt>
76 <span class=
"inheritName">Object
</span>
81 <li class=
"next">Lyricli::Configuration
</li>
84 <a href=
"#" class=
"inheritanceTree">show all
</a>
96 <dt class=
"r2 last">Defined in:
</dt>
97 <dd class=
"r2 last">lib/lyricli/configuration.rb
</dd>
100 <div class=
"clear"></div>
102 <h2>Overview
</h2><div class=
"docstring">
103 <div class=
"discussion">
105 This class handles the configuration of Lyricli
115 <h2>Constant Summary
</h2>
117 <dl class=
"constants">
119 <dt id=
"instance-classvariable" class=
"">@@instance =
122 <dd><pre class=
"code"><span class='const'
>Configuration
</span><span class='period'
>.
</span><span class='id identifier rubyid_new'
>new
</span></pre></dd>
136 <small>(
<a href=
"#" class=
"summary_toggle">collapse
</a>)
</small>
142 <span class=
"summary_signature">
144 <a href=
"#instance-class_method" title=
"instance (class method)">+ (Object)
<strong>instance
</strong> </a>
158 <span class=
"summary_desc"><div class='inline'
><p>
159 Ensure this is only called once.
169 Instance Method Summary
170 <small>(
<a href=
"#" class=
"summary_toggle">collapse
</a>)
</small>
176 <span class=
"summary_signature">
178 <a href=
"#%5B%5D-instance_method" title=
"#[] (instance method)">- (String, ...)
<strong>[]
</strong>(key)
</a>
192 <span class=
"summary_desc"><div class='inline'
><p>
193 Access configuration properties, loads config if needed beforehand.
201 <span class=
"summary_signature">
203 <a href=
"#%5B%5D%3D-instance_method" title=
"#[]= (instance method)">- (Object)
<strong>[]=
</strong>(key, value)
</a>
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.
227 <span class=
"summary_signature">
229 <a href=
"#delete-instance_method" title=
"#delete (instance method)">- (Object)
<strong>delete
</strong>(key)
</a>
243 <span class=
"summary_desc"><div class='inline'
><p>
244 Deletes a key from the configuration, loads config if needed and saves it
253 <span class=
"summary_signature">
255 <a href=
"#initialize-instance_method" title=
"#initialize (instance method)">- (Configuration)
<strong>initialize
</strong> </a>
262 <span class=
"note title constructor">constructor
</span>
271 <span class=
"summary_desc"><div class='inline'
><p>
272 Defines the paths to the default and user configuration files.
280 <span class=
"summary_signature">
282 <a href=
"#load_config-instance_method" title=
"#load_config (instance method)">- (Object)
<strong>load_config
</strong> </a>
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
’s not present.
306 <span class=
"summary_signature">
308 <a href=
"#save_config-instance_method" title=
"#save_config (instance method)">- (Object)
<strong>save_config
</strong> </a>
322 <span class=
"summary_desc"><div class='inline'
><p>
323 Serializes the `@config` Hash to JSON and saves it to a file.
333 <div id=
"constructor_details" class=
"method_details_list">
334 <h2>Constructor Details
</h2>
336 <div class=
"method_details first">
337 <h3 class=
"signature first" id=
"initialize-instance_method">
339 - (
<tt><span class='object_link'
><a href=
"" title=
"Lyricli::Configuration (class)">Configuration
</a></span></tt>)
<strong>initialize
</strong>
345 </h3><div class=
"docstring">
346 <div class=
"discussion">
348 Defines the paths to the default and user configuration files
357 </div><table class=
"source_code">
370 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
7</span>
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'
>"</span><span class='tstring_content'
>~/.lyricli.conf
</span><span class='tstring_end'
>"</span></span>
374 <span class='ivar'
>@defaults_path
</span> <span class='op'
>=
</span> <span class='tstring'
><span class='tstring_beg'
>"</span><span class='tstring_content'
>defaults.json
</span><span class='tstring_end'
>"</span></span>
375 <span class='ivar'
>@config
</span> <span class='op'
>=
</span> <span class='kw'
>nil
</span>
376 <span class='kw'
>end
</span></pre>
385 <div id=
"class_method_details" class=
"method_details_list">
386 <h2>Class Method Details
</h2>
389 <div class=
"method_details first">
390 <h3 class=
"signature first" id=
"instance-class_method">
392 + (
<tt>Object
</tt>)
<strong>instance
</strong>
398 </h3><div class=
"docstring">
399 <div class=
"discussion">
401 Ensure this is only called once. Only use the instance class variable to
402 access this method, as its constructor is private.
411 </div><table class=
"source_code">
422 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
17</span>
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>
434 <div id=
"instance_method_details" class=
"method_details_list">
435 <h2>Instance Method Details
</h2>
438 <div class=
"method_details first">
439 <h3 class=
"signature first" id=
"[]-instance_method">
441 - (
<tt>String
</tt>, ...)
<strong>[]
</strong>(key)
447 </h3><div class=
"docstring">
448 <div class=
"discussion">
450 Access configuration properties, loads config if needed beforehand.
457 <p class=
"tag_title">Parameters:
</p>
462 <span class='name'
>key
</span>
465 <span class='type'
>(
<tt>String
</tt>)
</span>
470 <div class='inline'
><p>
471 the configuration key to access
479 <p class=
"tag_title">Returns:
</p>
485 <span class='type'
>(
<tt>String
</tt>,
<tt>Hash
</tt>,
<tt>Array
</tt>)
</span>
490 <div class='inline'
><p>
491 the value of the configuration key.
499 </div><table class=
"source_code">
511 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
25</span>
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>
522 <div class=
"method_details ">
523 <h3 class=
"signature " id=
"[]=-instance_method">
525 - (
<tt>Object
</tt>)
<strong>[]=
</strong>(key, value)
531 </h3><div class=
"docstring">
532 <div class=
"discussion">
534 Assigns a new value to a configuration key, loads config if needed and
535 saves it after updating.
542 <p class=
"tag_title">Parameters:
</p>
547 <span class='name'
>key
</span>
550 <span class='type'
>(
<tt>String
</tt>)
</span>
555 <div class='inline'
><p>
556 the configuration key to set
564 <span class='name'
>value
</span>
567 <span class='type'
>(
<tt>Object
</tt>)
</span>
572 <div class='inline'
><p>
573 the value for the configuration key, can be any object as long as it can be
583 </div><table class=
"source_code">
596 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
36</span>
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>
608 <div class=
"method_details ">
609 <h3 class=
"signature " id=
"delete-instance_method">
611 - (
<tt>Object
</tt>)
<strong>delete
</strong>(key)
617 </h3><div class=
"docstring">
618 <div class=
"discussion">
620 Deletes a key from the configuration, loads config if needed and saves it
628 <p class=
"tag_title">Parameters:
</p>
633 <span class='name'
>key
</span>
636 <span class='type'
>(
<tt>String
</tt>)
</span>
641 <div class='inline'
><p>
651 </div><table class=
"source_code">
664 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
46</span>
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>
676 <div class=
"method_details ">
677 <h3 class=
"signature " id=
"load_config-instance_method">
679 - (
<tt>Object
</tt>)
<strong>load_config
</strong>
685 </h3><div class=
"docstring">
686 <div class=
"discussion">
688 Loads the configuration from the user file, attempts to create it from
689 defaults if it
’s not present. sets the `@config` instance variable.
698 </div><table class=
"source_code">
716 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
56</span>
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>
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'
>"</span><span class='tstring_content'
>r
</span><span class='tstring_end'
>"</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>
733 <div class=
"method_details ">
734 <h3 class=
"signature " id=
"save_config-instance_method">
736 - (
<tt>Object
</tt>)
<strong>save_config
</strong>
742 </h3><div class=
"docstring">
743 <div class=
"discussion">
745 Serializes the `@config` Hash to JSON and saves it to a file.
754 </div><table class=
"source_code">
768 <pre class=
"code"><span class=
"info file"># File 'lib/lyricli/configuration.rb', line
68</span>
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'
>"</span><span class='tstring_content'
>w
</span><span class='tstring_end'
>"</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>
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).