Class: Rbnotes::Conf

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/rbnotes/conf.rb

Overview

Holds the configuration settings. Each value of setting can be retrieved like a Hash object. Here is some examples.

conf = Rbnotes.conf
type = conf[:repository_type]
name = conf[:repository_name]
base = conf[:repository_base]

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

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.expand_path(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

#freezeObject



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

#taintObject



91
# File 'lib/rbnotes/conf.rb', line 91

def taint;   @conf.taint;   super; end

#untaintObject



92
# File 'lib/rbnotes/conf.rb', line 92

def untaint; @conf.untaint; super; end