lib/probe_dock_ruby/config.rb in probedock-ruby-0.1.0 vs lib/probe_dock_ruby/config.rb in probedock-ruby-0.1.1

- old
+ new

@@ -1,22 +1,15 @@ require 'yaml' -# Utilities to send test results to Probe Dock. module ProbeDockProbe def self.config - @config ||= Config.new.tap(&:load!) + @config ||= Config.new end - def self.configure options = {} - - yield config if block_given? - - config.check! - config.load_warnings.each{ |w| warn Paint["Probe Dock - #{w}", :yellow] } - - config + def self.config= config + @config = config end class Config # TODO: add silent/verbose option(s) class Error < ProbeDockProbe::Error; end @@ -57,13 +50,13 @@ @server.clear @servers.clear @load_warnings = [] - return unless config = load_config_files + config = load_config_files - @publish = parse_env_flag :publish, !!config[:publish] + @publish = parse_env_flag :publish, config.fetch(:publish, true) @server_name = parse_env_option(:server) || config[:server] @local_mode = parse_env_flag(:local) || !!config[:local] self.workspace = parse_env_option(:workspace) || config[:workspace] @print_payload = parse_env_flag :print_payload, !!config[:payload][:print] @@ -85,13 +78,20 @@ project_options = config[:project] project_options.merge! api_id: @server.project_api_id if @server and @server.project_api_id @project.update project_options + yield self if block_given? + + check! + @load_warnings.each{ |w| warn Paint["Probe Dock - #{w}", :yellow] } + self end + private + def check! configs = [ home_config_file, working_config_file ] actual_configs = configs.select{ |f| File.exists? f } @@ -104,12 +104,10 @@ elsif !@server_name && !@server.name @load_warnings << "No server name given" end end - private - def build_servers config default_server_options = { project_api_id: config[:project][:api_id] } servers = config[:servers].inject({}) do |memo,(name, options)| memo[name] = Server.new default_server_options.merge(options).merge(name: name) @@ -121,10 +119,10 @@ def load_config_files configs = [ home_config_file, working_config_file ] actual_configs = configs.select{ |f| File.exists? f } - return false if actual_configs.empty? + return { servers: [], payload: {}, project: {} } if actual_configs.empty? actual_configs.collect!{ |f| YAML.load_file f } actual_configs.inject({ servers: {} }) do |memo,yml| memo.merge! parse_general_options(yml)