Sha256: 6ac1e7a5460b446cf9507d717bfc854f77667e0cc6b49104be6e482b7733e44d

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 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)
      File.open(config_path, "r+") do |file|
        file.write JSON.pretty_generate(read_config.merge(opts))
      end
    end

    def read_config
      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

3 entries across 3 versions & 1 rubygems

Version Path
kosmos-0.0.2.pre.test4 lib/kosmos.rb
kosmos-0.0.2.pre.test3 lib/kosmos.rb
kosmos-0.0.2 lib/kosmos.rb