class Patriot::Util::Config::IniFileConfig
a configuration implementation definied by the ini-file format
Constants
- COMMON_SECTION
common section name
Public Class Methods
new(path, type = nil)
click to toggle source
@param path [String] path to a configuration file @param type [String] load type (section name to be loaded)
# File lib/patriot/util/config/inifile_config.rb, line 13 def initialize(path, type = nil) raise "path in String is expected but #{path.class}" unless path.is_a?(String) @path = path config = IniFile.load(path) raise "#{path} not found" if config.nil? @config = {} read_section(config, COMMON_SECTION) read_section(config, type) end
Public Instance Methods
get(name, default=nil)
click to toggle source
@see Patriot::Util::Config::Base
# File lib/patriot/util/config/inifile_config.rb, line 40 def get(name, default=nil) v = @config[name.to_sym] v = split_value(v) return v.nil? ? default : v end
path()
click to toggle source
@see Patriot::Util::Config::Base
# File lib/patriot/util/config/inifile_config.rb, line 35 def path return @path end
Private Instance Methods
read_section(config, section)
click to toggle source
@private read configuration from a section @param config [IniFile] ini file configuration @param section [String] section name
# File lib/patriot/util/config/inifile_config.rb, line 27 def read_section(config, section) sect = config[section] return if sect.nil? sect.each{|k,v| @config[k.to_sym] = v } end
split_value(value, delimiter = ',')
click to toggle source
split configuration value by a delimiter @param value [String] the value to be splitted @param delimiter [String] delimiter for splitting
# File lib/patriot/util/config/inifile_config.rb, line 49 def split_value(value, delimiter = ',') # don't allow spaces around value regexp = Regexp.new("\\s*#{delimiter}\\s*") if value.is_a?(String) && value =~ regexp return value.split(regexp) else return value end end