Class: Patriot::Util::Config::IniFileConfig

Inherits:
Base
  • Object
show all
Defined in:
lib/patriot/util/config/inifile_config.rb

Overview

a configuration implementation definied by the ini-file format

Constant Summary collapse

COMMON_SECTION =

common section name

'common'

Instance Method Summary collapse

Constructor Details

#initialize(path, type = nil) ⇒ IniFileConfig

Returns a new instance of IniFileConfig.

Parameters:

  • path (String)

    path to a configuration file

  • type (String) (defaults to: nil)

    load type (section name to be loaded)



13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

#get(name, default = nil) ⇒ Object

See Also:



40
41
42
43
44
# 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

#pathObject

See Also:



35
36
37
# File 'lib/patriot/util/config/inifile_config.rb', line 35

def path
  return @path
end