Module: CLI::Config

Defined in:
lib/robot_sweatshop/cli/config.rb

Overview

Methods for configuring Robot Sweatshop

Class Method Summary collapse

Class Method Details

.compile_to_fileObject



31
32
33
34
35
# File 'lib/robot_sweatshop/cli/config.rb', line 31

def self.compile_to_file
  config = expand_paths_in configatron.to_h
  config[:working_path] = Dir.pwd
  write config
end

.defaultObject



7
8
9
# File 'lib/robot_sweatshop/cli/config.rb', line 7

def self.default
  File.read "#{__dir__}/../../../config.defaults.yaml"
end

.expand_paths_in(config_hash) ⇒ Object



19
20
21
22
23
# File 'lib/robot_sweatshop/cli/config.rb', line 19

def self.expand_paths_in(config_hash)
  config_hash.each do |key, value|
    config_hash[key] = File.expand_path value if key.to_s.match(/_path/)
  end
end

.path(for_user: false) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/robot_sweatshop/cli/config.rb', line 11

def self.path(for_user: false)
  if for_user
    '~/.robot_sweatshop/config.yaml'
  else
    '.robot_sweatshop/config.yaml'
  end
end

.write(config_hash) ⇒ Object



25
26
27
28
29
# File 'lib/robot_sweatshop/cli/config.rb', line 25

def self.write(config_hash)
  config_home = File.expand_path('~/.robot_sweatshop')
  FileUtils.mkpath config_home
  File.write "#{config_home}/compiled_config.yaml", config_hash.to_yaml
end