class Chid::Commands::Install

Attributes

chid_config_path[R]

Public Class Methods

new(chid_config_path) click to toggle source
# File lib/chid/commands/install.rb, line 6
def initialize(chid_config_path)
  @chid_config_path = chid_config_path
end

Public Instance Methods

run() click to toggle source
# File lib/chid/commands/install.rb, line 10
def run
  create_or_update_chid_config_file
end

Private Instance Methods

chid_config_file_exist?() click to toggle source
# File lib/chid/commands/install.rb, line 48
def chid_config_file_exist?
  File.exist?(chid_config_path)
end
chid_configurations() click to toggle source
# File lib/chid/commands/install.rb, line 32
def chid_configurations
  base_config = {
    chid: {
      workstations: {}
    }
  }

  if chid_config_file_exist?
    data = YAML.load_file chid_config_path
    data[:chid][:workstations] = data[:chid].fetch(:workstations, {})
    base_config = data
  end

  base_config
end
create_or_update_chid_config_file() click to toggle source
# File lib/chid/commands/install.rb, line 18
def create_or_update_chid_config_file
  print "\n--- Installing chid ---\n "
  print "\nCreating the " unless chid_config_file_exist?
  print "\nUpdating the " if chid_config_file_exist?
  print "~/.chid.config ".blue
  print "file\n"

  base_config = chid_configurations

  File.open(chid_config_path, 'w') do |file|
    YAML.dump(base_config, file)
  end
end