class RComp::Conf

Constants

CONF_PATH

Conf file path

DEFAULT

Default configuration options

VALID_KEYS

Valid configuraiton keys

Attributes

command[R]
expected_root[R]
ignore[R]
result_root[R]
root[R]
test_root[R]
timeout[R]

Public Class Methods

new() click to toggle source

Initialize a new config object

Loads options from config file, merges with defaults and stores everything in memory

# File lib/rcomp/conf.rb, line 30
def initialize
  # Load custom configuration and merge it with defaults
  @custom = read_conf_file
  @conf = DEFAULT.merge(@custom)

  # Load configuration values into attributes
  @command = @conf['command']
  @ignore = @conf['ignore'] || []
  @timeout = @conf['timeout']
  @root = @conf['directory']
  @test_root = @root + '/tests'
  @result_root = @root + '/results'
  @expected_root = @root + '/expected'
end

Public Instance Methods

set_command(command) click to toggle source

Set a command as a custom configuration value

Returns nothing

# File lib/rcomp/conf.rb, line 48
def set_command(command)
  @custom['command'] = command
  puts "Command set to #{command}"
  write_conf_file
end

Private Instance Methods

read_conf_file() click to toggle source

Read the config options from RComp’s configuration file

Returns a Hash of config options

# File lib/rcomp/conf.rb, line 68
def read_conf_file
  conf = {}
  if File.exists?(CONF_PATH) && File.size?(CONF_PATH)
    # Store valid conf keys
    YAML.load_file(CONF_PATH).each do |key, value|
      if VALID_KEYS.include? key
        conf[key] = value
      else
        say "Invalid configuration key: #{key}"
      end
    end
  end
  conf
end
write_conf_file() click to toggle source

Write the current custom config options to the config file

Returns nothing

# File lib/rcomp/conf.rb, line 59
def write_conf_file
  touch CONF_PATH
  conf_file = File.open(CONF_PATH, 'w')
  conf_file.puts YAML.dump @custom
end