class KubsCLI::Install

Used to install items from a YAML file

Public Class Methods

new(config = KubsCLI.configuration) click to toggle source
# File lib/kubs_cli/install.rb, line 6
def initialize(config = KubsCLI.configuration)
  @fh = FileHelper.new
  @dependencies = config.dependencies
  @packages = config.packages
end

Public Instance Methods

create_ary_from_yaml(file) click to toggle source

Installs dependencies from a given YAML file @see lib/examples/dependencies.yaml @return Array<String> Returns an array of strings to run via Rake to install

various packages
# File lib/kubs_cli/install.rb, line 24
def create_ary_from_yaml(file)
  hash = @fh.load_yaml(file)
  hash.map do |_key, value|
    command = value['command']

    packages = value['packages']
    packages = packages.join(' ') if packages.is_a?(Array)

    "#{command} #{packages}"
  end
rescue StandardError => e
  msg = "There was an issue with creating a dependencies array from #{file}"
  KubsCLI.add_error(e: e, msg: msg)
end
install_dependencies() click to toggle source
# File lib/kubs_cli/install.rb, line 12
def install_dependencies
  install_from_file(@dependencies)
end
install_from_file(file) click to toggle source

Installs dependencies from a give yaml_file via Rake.sh @return void

# File lib/kubs_cli/install.rb, line 41
def install_from_file(file)
  ary = create_ary_from_yaml(file)

  ary.each do |command|
    Rake.sh(command.to_s)
  rescue StandardError => e
    KubsCLI.add_error(e: e, msg: "Failed with #{command}")
  end
end
install_packages() click to toggle source
# File lib/kubs_cli/install.rb, line 16
def install_packages
  install_from_file(@packages)
end