Class: PostRunner::RuntimeConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/postrunner/RuntimeConfig.rb

Overview

Simple class to manage runtime configuration options which are persisted in a YAML file.

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ RuntimeConfig

Create a new RC object.

Parameters:

  • dir (String)

    the directory to hold the config.yml file.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/postrunner/RuntimeConfig.rb', line 25

def initialize(dir)
  @options = {
    :version => '0.0.0',
    :unit_system => :metric,
    :import_dir => nil,
    :html_dir => File.join(dir, 'html')
  }
  @config_file = File.join(dir, 'config.yml')

  load_options if File.exist?(@config_file)
end

Instance Method Details

#[](name) ⇒ Object

Shortcut for get_option.

Parameters:

  • name (Symbol)

    the name of the config option.

Returns:

  • (Object)

    the value of the config option.



40
41
42
# File 'lib/postrunner/RuntimeConfig.rb', line 40

def [](name)
  get_option(name)
end

#get_option(name) ⇒ Object

Get a config option value.

Parameters:

  • name (Symbol)

    the name of the config option.

Returns:

  • (Object)

    the value of the config option.



47
48
49
# File 'lib/postrunner/RuntimeConfig.rb', line 47

def get_option(name)
  @options[name]
end

#set_option(name, value) ⇒ Object

Set a config option and update the RC file.

Parameters:

  • name (Symbol)

    The name of the config option.

  • value (Object)

    The value of the config option.



54
55
56
57
# File 'lib/postrunner/RuntimeConfig.rb', line 54

def set_option(name, value)
  @options[name] = value
  save_options
end