class Rspawn::Config

Public Class Methods

new(root, key, cli_options) click to toggle source
# File lib/rspawn/config.rb, line 4
def initialize(root, key, cli_options)
  @root = root
  @key = key
  @cli_options = cli_options
end

Public Instance Methods

config_dir() click to toggle source
# File lib/rspawn/config.rb, line 14
def config_dir
  File.dirname(config_path)
end
config_path() click to toggle source
# File lib/rspawn/config.rb, line 10
def config_path
  "#{@root}/#{@key}/config.yml"
end
load() click to toggle source
# File lib/rspawn/config.rb, line 18
def load
  File.exist?(config_path) ? JSON.parse(File.read(config_path)) : {}
end
option(command = nil) click to toggle source
# File lib/rspawn/config.rb, line 33
def option(command = nil)
  option = {}
  save_option = load
  option[:working_dir] = @cli_options['working_dir'] || save_option['working_dir'] || Dir.pwd
  FileUtils.mkdir_p(option[:working_dir])
  Dir::chdir(option[:working_dir])

  option[:log_file] = @cli_options['log_file'] || save_option['log_file'] || config_dir + '/' + @key + '.log'
  option[:pid_file] = @cli_options['pid_file'] || save_option['pid_file'] || config_dir + '/' + @key + '.pid'
  option[:timeout] = @cli_options['timeout'] || save_option['timeout'] || 10
  option[:processes] = @cli_options['processes'] || save_option['processes'] || 1
  command = command || save_option['command']
  return option, command
end
remove() click to toggle source
# File lib/rspawn/config.rb, line 29
def remove
  FileUtils.rm_rf(config_dir)
end
save(option, command) click to toggle source
# File lib/rspawn/config.rb, line 22
def save(option, command)
  FileUtils.mkdir_p(config_dir)
  output = option.to_h
  output[:command] = command || output[:command]
  File.write(config_path, output.to_json)
end