Class: Rbnotes::Conf
- Inherits:
-
Object
- Object
- Rbnotes::Conf
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/rbnotes/conf.rb
Overview
Constant Summary collapse
- FILENAME_CONF =
Name of the file to store configuration settings.
"config.yml"
- DIRNAME_RBNOTES =
Name of the directory indicates which belongs to “rbnotes”.
"rbnotes"
- DIRNAME_COMMON_CONF =
Name of the directory which is used to indicate to put configuration files. Many tools use this name as the role.
".config"
- NUMBER_OF_RECENT_NOTES =
Name of the number of notes to enumerate. The values is referred only to enumerate the recent notes.
10
Instance Method Summary collapse
-
#[](sym) ⇒ Object
Retrieves the value for the given key.
- #freeze ⇒ Object
-
#initialize(path = nil) ⇒ Conf
constructor
:nodoc:.
-
#initialize_copy(_) ⇒ Object
:stopdoc:.
- #taint ⇒ Object
- #untaint ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Conf
:nodoc:
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rbnotes/conf.rb', line 40 def initialize(path = nil) # :nodoc: @conf = {} unless path.nil? abspath = File.(path) raise NoConfFileError, path unless FileTest.exist?(abspath) @conf[:path] = abspath else @conf[:path] = default_conf_path end values = if FileTest.exist?(@conf[:path]) yaml_str = File.open(@conf[:path], "r") { |f| f.read } YAML.load(yaml_str) else DEFAULT_VALUES end @conf.merge!(values) @conf[:config_home] = config_home end |
Instance Method Details
#[](sym) ⇒ Object
Retrieves the value for the given key.
:call-seq:
self[sym] -> value
75 76 77 78 79 80 81 82 |
# File 'lib/rbnotes/conf.rb', line 75 def [](sym) mode = @conf[:run_mode] || :production value = @conf[sym] || DEFAULT_VALUES[sym] if [:repository_name].include?(sym) value += MODE_POSTFIX[mode] end value end |
#freeze ⇒ Object
90 |
# File 'lib/rbnotes/conf.rb', line 90 def freeze; @conf.freeze; super; end |
#initialize_copy(_) ⇒ Object
:stopdoc:
86 87 88 |
# File 'lib/rbnotes/conf.rb', line 86 def initialize_copy(_) @conf = @conf.dup end |
#taint ⇒ Object
91 |
# File 'lib/rbnotes/conf.rb', line 91 def taint; @conf.taint; super; end |
#untaint ⇒ Object
92 |
# File 'lib/rbnotes/conf.rb', line 92 def untaint; @conf.untaint; super; end |