Sha256: c28e1477019e9c2d04b9a4c7711fffbd24fea8e4bcdb69959ec25c2a2ea2a631

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module KubsCLI
  # Used for keeping a consistent config across the entire project
  class Configuration
    # local files
    attr_accessor :local_dir

    # Dependencies to install
    attr_accessor :dependencies
    attr_accessor :packages

    # remote files to be used
    attr_accessor :config_files, :dotfiles, :gnome_terminal_settings

    def initialize
      # Values for items to be copied to
      @local_dir = Dir.home

      # values for items to be copied from
      # set to nil so that someone must set a path
      @config_files = nil
      @dotfiles = nil
      @packages = nil
      @gnome_terminal_settings = nil
      @dependencies = nil
    end
  end

  def self.configure
    @configuration ||= Configuration.new
    yield(configuration)
  end

  def self.configuration
    @configuration ||= Configuration.new
  end

  def self.reset_configuration
    @configuration = Configuration.new
  end

  def self.load_configuration(file = File.join(Dir.home, '.kubs', 'config.rb'))
    msg = 'Unable to location a configuration file. The default location is'
    msg += '$HOME/.kubs/config.rb'
    msg += "\nTo create a standard default config, run 'kubs init'"

    raise Exception, msg unless File.exist?(file)

    load file
  end

  def self.create_config_dir(path = File.join(Dir.home, '.kubs'))
    fh = FileHelper.new

    puts "Creating a default configuration files @ #{path}"
    fh.mkdirs(path)

    Dir["#{EXAMPLES}/*"].each do |file|
      fh.copy(from: file, to: path)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kubs_cli-0.2.2 lib/kubs_cli/configuration.rb
kubs_cli-0.2.1 lib/kubs_cli/configuration.rb
kubs_cli-0.2.0 lib/kubs_cli/configuration.rb
kubs_cli-0.1.15 lib/kubs_cli/configuration.rb