Class: Rspawn::Config
- Inherits:
-
Object
- Object
- Rspawn::Config
- Defined in:
- lib/rspawn/config.rb
Instance Method Summary collapse
- #config_dir ⇒ Object
- #config_path ⇒ Object
-
#initialize(root, key, cli_options) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #option(command = nil) ⇒ Object
- #remove ⇒ Object
- #save(option, command) ⇒ Object
Constructor Details
Instance Method Details
#config_dir ⇒ Object
14 15 16 |
# File 'lib/rspawn/config.rb', line 14 def config_dir File.dirname(config_path) end |
#config_path ⇒ Object
10 11 12 |
# File 'lib/rspawn/config.rb', line 10 def config_path "#{@root}/#{@key}/config.yml" end |
#load ⇒ Object
18 19 20 |
# File 'lib/rspawn/config.rb', line 18 def load File.exist?(config_path) ? JSON.parse(File.read(config_path)) : {} end |
#option(command = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/rspawn/config.rb', line 29 def remove FileUtils.rm_rf(config_dir) end |
#save(option, command) ⇒ Object
22 23 24 25 26 27 |
# 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 |