Class: RBatch::Config
- Inherits:
-
Object
- Object
- RBatch::Config
- Defined in:
- lib/rbatch/config.rb
Instance Method Summary (collapse)
-
- (Object) [](key)
Config value.
-
- (Boolean) exist?
Config file exists or not.
-
- (Config) initialize(path)
constructor
A new instance of Config.
-
- (String) path
Config file path.
- - (Hash) to_h
- - (String) to_s
Constructor Details
- (Config) initialize(path)
Returns a new instance of Config
14 15 16 17 18 19 20 21 |
# File 'lib/rbatch/config.rb', line 14 def initialize(path) @path = path begin @hash = ConfigElement.new(YAML::load_file(@path)) rescue Errno::ENOENT => e @hash = nil end end |
Instance Method Details
- (Object) [](key)
Config value
26 27 28 29 30 31 32 |
# File 'lib/rbatch/config.rb', line 26 def[](key) if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @hash[key] end end |
- (Boolean) exist?
Config file exists or not
40 |
# File 'lib/rbatch/config.rb', line 40 def exist? ; ! @hash.nil? ; end |
- (String) path
Config file path
36 |
# File 'lib/rbatch/config.rb', line 36 def path ; @path ; end |
- (Hash) to_h
43 44 45 46 47 48 49 |
# File 'lib/rbatch/config.rb', line 43 def to_h if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @hash end end |
- (String) to_s
52 53 54 55 56 57 58 |
# File 'lib/rbatch/config.rb', line 52 def to_s if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @hash.to_s end end |