class RBatch::Config
Public Class Methods
new(path,is_erb = false)
click to toggle source
@param [String] path Config
file path
# File lib/rbatch/config.rb, line 14 def initialize(path,is_erb = false) @path = path begin if is_erb @element = Config.parse(YAML::load(ERB.new(IO.read(@path)).result)) else @element = Config.parse(YAML::load_file(@path)) end rescue Errno::ENOENT => e @element = nil end end
parse(yaml)
click to toggle source
@return ConfigElementArray
or ConfigElementHash
# File lib/rbatch/config.rb, line 65 def Config.parse(yaml) if yaml.class == Hash return ConfigElementHash.new(yaml) elsif yaml.class == Array return ConfigElementArray.new(yaml) else return yaml end end
Public Instance Methods
[](key)
click to toggle source
exist?()
click to toggle source
Config
file exists or not @return [Boolean]
# File lib/rbatch/config.rb, line 44 def exist? ; ! @element.nil? ; end
path()
click to toggle source
Config
file path @return [String]
# File lib/rbatch/config.rb, line 40 def path ; @path ; end
to_h()
click to toggle source
@return [Hash]
# File lib/rbatch/config.rb, line 47 def to_h if @element.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @element end end
to_s()
click to toggle source
@return [String]
# File lib/rbatch/config.rb, line 56 def to_s if @element.nil? raise RBatch::ConfigException, "Config file \"#{@path}\" does not exist" else @element.to_s end end