Module: Patriot::Util::Config

Included in:
Controller::PackageController, Controller::WorkerAdminController, Tool::PatriotCommand, Logger, Worker::InfoServer
Defined in:
lib/patriot/util/config.rb,
lib/patriot/util/config/base.rb,
lib/patriot/util/config/inifile_config.rb

Overview

namespace for configuration files

Defined Under Namespace

Classes: Base, IniFileConfig

Constant Summary collapse

DEFAULT_CONFIG =

the path to default configuration file

File.join($home || Dir.pwd, 'config', 'patriot.ini')
PLUGIN_KEY =

a configuration parameter key for plugins

"plugins"
PLUGIN_DIR_KEY =

a configuration parameter key for plugins directory

"plugins.dir"
DEFAULT_PLUGIN_DIR =

default plugins directory

"plugins"
PLUGIN_LIB_DIR =

plugin directory

'lib'
PLUGIN_INIT_SCRIPT =

plugin initiation script

'init.rb'
ADMIN_USER_KEY =

admin user to access remote host

'admin_user'
WORKER_USER_KEY =

user who runs worker

'worker_user'
WORKER_HOST_KEY =

a comma separated list of hosts where workers are running

'worker_hosts'
INFO_SERVER_PORT_KEY =

port number used by info server

'info_server_port'
USERNAME_KEY =

configuratio key for admin user name

'info_server.admin.username'
PASSWORD_KEY =

configuratio key for admin password

'info_server.admin.password'

Instance Method Summary collapse

Instance Method Details

#load_config(option = {}) ⇒ Object

load configuration file

Parameters:

  • option (Hash) (defaults to: {})

Options Hash (option):

  • :path (String)

    path to configuration file

  • :type (String)

    load type (differe by tool)

  • :ignore_plugin (Boolean)

    set true not to load plugins



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/patriot/util/config.rb', line 41

def load_config(option = {})
  option = {:path => DEFAULT_CONFIG,
            :type => nil,
            :ignore_plugin => false }.merge(option)
  conf = nil
  case File.extname(option[:path])
  when '.ini'
    conf = Patriot::Util::Config::IniFileConfig.new(option[:path], option[:type])
  else
    raise "unsupported config file name: #{conf[:path]}"
  end
  load_plugins(conf) unless option[:ignore_plugin]
  return conf
end

#load_plugins(conf) ⇒ Object

load plugins

Parameters:



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/patriot/util/config.rb', line 58

def load_plugins(conf)
  plugins = conf.get(PLUGIN_KEY)
  return conf if plugins.nil?
  plugins = [plugins] unless plugins.is_a?(Array)
  plugin_dir = conf.get(PLUGIN_DIR_KEY, DEFAULT_PLUGIN_DIR)
  plugins.each do |plugin|
    path = File.join($home, plugin_dir, plugin)
    init_script = File.join(path, PLUGIN_INIT_SCRIPT)
    raise "Failed to load #{plugin}: #{init_script} does not exist" unless File.file?(init_script)
    $: << File.join(path, PLUGIN_LIB_DIR)
    require init_script
  end
end