lib/fulmar/domain/service/configuration_service.rb in fulmar-1.5.2 vs lib/fulmar/domain/service/configuration_service.rb in fulmar-1.6.0

- old
+ new

@@ -11,23 +11,26 @@ FULMAR_CONFIGURATION = 'FulmarConfiguration' FULMAR_CONFIGURATION_DIR = 'Fulmar' DEPLOYMENT_CONFIG_FILE = 'deployment.yml' BLANK_CONFIG = { + project: {}, environments: {}, features: {}, hosts: {}, dependencies: { all: {} } } include Singleton attr_reader :environment, :target + attr_accessor :load_user_config def initialize @environment = nil @target = nil + @load_user_config = true end # Allow access of configuration via array/hash access methods (read access) def [](id) ready? ? configuration[:environments][@environment][@target][id] : nil @@ -118,14 +121,21 @@ configuration[:environments][@environment][@target] = other.deep_merge(configuration[:environments][@environment][@target]) end def config_files files = Dir.glob(File.join(base_path, FULMAR_CONFIGURATION_DIR, '*.config.yml')).sort - files << "#{ENV['HOME']}/.fulmar.yml" if File.exist? "#{ENV['HOME']}/.fulmar.yml" + files << "#{ENV['HOME']}/.fulmar.yml" if File.exist?("#{ENV['HOME']}/.fulmar.yml") && @load_user_config files end + # Reset the loaded configuration, forcing a reload + # this is currently used for reloading the config without the user config file + # to test the project configuration + def reset + @config = nil + end + protected def lookup_base_path fulmar_file = Fulmar::Service::HelperService.reverse_file_lookup(Dir.pwd, FULMAR_FILE) @@ -143,15 +153,12 @@ @config[:environments][env][target] = @config[:environments][:all].deep_merge(@config[:environments][env][target]) if @config[:environments][:all] return if @config[:environments][env][target][:host].blank? host = @config[:environments][env][target][:host].to_sym - if @config[:hosts] && @config[:hosts][host] - @config[:hosts][host].each do - @config[:environments][env][target] = @config[:hosts][host].deep_merge(@config[:environments][env][target]) - end - else - fail "Host #{host} is not configured." + return unless @config[:hosts] && @config[:hosts][host] + @config[:hosts][host].each do + @config[:environments][env][target] = @config[:hosts][host].deep_merge(@config[:environments][env][target]) end end # Loads the configuration from the YAML file and populates all targets def load_configuration