Sha256: 463f150ffbb41140b2bca316f9ba67857b5cbb8791011820bd276550efd40d77

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

require 'kosmos/package_dsl'
require 'kosmos/package_attrs'
require 'kosmos/package_downloads'
require 'kosmos/package'
require 'kosmos/versioner'
require 'kosmos/git_adapter'
require 'kosmos/download_url'
require 'kosmos/user_interface'
require 'kosmos/web/app'
require 'kosmos/util'
require 'kosmos/version'

require 'json'

module Kosmos
  class << self
    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
    end

    def save_ksp_path(path)
      write_config(ksp_path: path)
    end

    def load_ksp_path
      read_config[:ksp_path]
    end

    def cache_dir
      read_config[:cache_dir]
    end

    private

    def write_config(opts)
      FileUtils.touch(config_path)

      config_to_write = JSON.pretty_generate(read_config.merge(opts))
      File.open(config_path, "w") do |file|
        file.write config_to_write
      end
    end

    def read_config
      FileUtils.touch(config_path)

      config = File.read(config_path)
      if config.empty?
        {}
      else
        JSON.parse(config, symbolize_names: true)
      end
    end

    def config_path
      File.join(Dir.home, ".kosmos")
    end
  end

  class Configuration
    attr_accessor :verbose, :post_processors, :output_method

    def initialize
      @verbose = false
      @post_processors = [Kosmos::PostProcessors::ModuleManagerResolver]
      @output_method = Proc.new { |str| puts str }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kosmos-0.0.5 lib/kosmos.rb
kosmos-0.0.4 lib/kosmos.rb