Parent

RBatch::CommonConfig

Common-config Reader

Read common config file and return hash opject. If the key does not exist in config file, raise RBatch::CommonConfig::Exception.

Default common config file path is “${RB_HOME}/conf/common.yaml“

Sample

config : ${RB_HOME}/conf/common.yaml

 key: value
 array:
  * item1
  * item2
  * item3

script : ${RB_HOME}/bin/sample.rb

 require 'rbatch'
 p RBatch::common_config
 => {"key" => "value", "array" => ["item1", "item2", "item3"]}

Public Class Methods

new() click to toggle source
    # File lib/rbatch/common_config.rb, line 26
26:     def initialize
27:       file = RBatch.run_conf[:common_conf_name]
28:       @path = File.join(RBatch.conf_dir,file)
29:       begin
30:         @hash = YAML::load_file(@path)
31:       rescue Errno::ENOENT => e
32:         @hash = nil
33:       end
34:     end

Public Instance Methods

[](key) click to toggle source
    # File lib/rbatch/common_config.rb, line 35
35:     def[](key)
36:       if @hash.nil?
37:         raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
38:       end
39:       if @hash[key].nil?
40:         if key.class == Symbol
41:           raise RBatch::CommonConfig::Exception, "Value of key(:#{key} (Symbol)) is nil. By any chance, dou you mistake key class Symbol for String?"
42:         elsif key.class == String
43:           raise RBatch::CommonConfig::Exception, "Value of key(\"#{key}\" (String)) is nil"
44:         else
45:           raise RBatch::CommonConfig::Exception, "Value of key(#{key}) is nil"
46:         end
47:       else
48:         @hash[key]
49:       end
50:     end
exist?() click to toggle source
    # File lib/rbatch/common_config.rb, line 52
52:     def exist? ; ! @hash.nil? ; end
path() click to toggle source
    # File lib/rbatch/common_config.rb, line 51
51:     def path ; @path ; end
to_h() click to toggle source
    # File lib/rbatch/common_config.rb, line 53
53:     def to_h
54:       if @hash.nil?
55:         raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
56:       else
57:         @hash
58:       end
59:     end
to_s() click to toggle source
    # File lib/rbatch/common_config.rb, line 60
60:     def to_s
61:       if @hash.nil?
62:         raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
63:       else
64:         @hash.to_s
65:       end
66:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.