Sha256: f89167a6d0d7e8f3aec2a7827998f715fb3be65bc8371db9235a04788f3ae8f4
Contents?: true
Size: 1.25 KB
Versions: 5
Compression:
Stored size: 1.25 KB
Contents
require 'yaml' require 'pathname' module RBatch class Config @path @hash def initialize(path) @path = path begin @hash = YAML::load_file(@path) rescue Errno::ENOENT => e @hash = nil end end def[](key) if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" end if @hash[key].nil? if key.class == Symbol raise RBatch::ConfigException, "Value of key(:#{key} (Symbol)) is nil. By any chance, dou you mistake key class Symbol for String?" elsif key.class == String raise RBatch::ConfigException, "Value of key(\"#{key}\" (String)) is nil" else raise RBatch::ConfigException, "Value of key(#{key}) is nil." end else @hash[key] end end def path ; @path ; end def exist? ; ! @hash.nil? ; end def to_h if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @hash end end def to_s if @hash.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @hash.to_s end end end class RBatch::ConfigException < StandardError ; end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
rbatch-2.1.6 | lib/rbatch/config.rb |
rbatch-2.1.5 | lib/rbatch/config.rb |
rbatch-2.1.4 | lib/rbatch/config.rb |
rbatch-2.1.3 | lib/rbatch/config.rb |
rbatch-2.1.2 | lib/rbatch/config.rb |