lib/kosmos.rb in kosmos-0.0.1 vs lib/kosmos.rb in kosmos-0.0.2.pre.test2

- old
+ new

@@ -1,14 +1,18 @@ 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' +require 'json/pure' module Kosmos class << self def config @config ||= Configuration.new @@ -24,31 +28,41 @@ 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, "rw+") do |file| + File.open(config_path, "r+") do |file| file.write JSON.pretty_generate(read_config.merge(opts)) end end def read_config - JSON.parse(File.read(config_path), symbolize_names: true) + 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 + 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