Class: OpenShift::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/openshift-origin-common/config.rb

Constant Summary collapse

CONF_DIR =
'/etc/openshift/'
PLUGINS_DIR =
File.join(CONF_DIR, 'plugins.d/')
NODE_CONF_FILE =
File.join(CONF_DIR, 'node.conf')

Instance Method Summary collapse

Constructor Details

#initialize(conf_path = NODE_CONF_FILE) ⇒ Config

Returns a new instance of Config.



26
27
28
29
30
31
32
33
# File 'lib/openshift-origin-common/config.rb', line 26

def initialize(conf_path=NODE_CONF_FILE)
  begin
    @conf = ParseConfig.new(conf_path)
  rescue Errno::EACCES => e
    puts "Could not open config file #{conf_path}: #{e.message}"
    exit 253
  end
end

Instance Method Details

#get(name, default = nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/openshift-origin-common/config.rb', line 35

def get(name, default=nil)
  val = @conf.get_value(name)
  val = default.to_s if (val.nil? and !default.nil?)
  val.gsub!(/\\:/,":") if not val.nil?
  val.gsub!(/[ \t]*#[^\n]*/,"") if not val.nil?
  val = val[1..-2] if not val.nil? and val.start_with? "\""
  val
end

#get_bool(name, default = nil) ⇒ Object



44
45
46
47
# File 'lib/openshift-origin-common/config.rb', line 44

def get_bool(name, default=nil)
  # !! is used to normalise the value to either a 1 (true) or a 0 (false).
  !!(get(name, default) =~ /^(true|t|yes|y|1)$/i)
end