lib/fulmar/domain/service/configuration_service.rb in fulmar-1.2.1 vs lib/fulmar/domain/service/configuration_service.rb in fulmar-1.3.0
- old
+ new
@@ -10,10 +10,17 @@
FULMAR_FILE = 'Fulmarfile'
FULMAR_CONFIGURATION = 'FulmarConfiguration'
FULMAR_CONFIGURATION_DIR = 'Fulmar'
DEPLOYMENT_CONFIG_FILE = 'deployment.yml'
+ BLANK_CONFIG = {
+ environments: {},
+ features: {},
+ hosts: {},
+ dependencies: { all: {} }
+ }
+
include Singleton
attr_reader :environment, :target
def initialize
@@ -58,10 +65,14 @@
def target=(target)
@target = target ? target.to_sym : nil
end
+ def dependencies(env = nil)
+ env.nil? ? @config[:dependencies][:all] : @config[:dependencies][:all].deep_merge(@config[:dependencies][env])
+ end
+
def ready?
return false if @environment.nil? || @target.nil?
fail 'Environment is invalid' if configuration[:environments][@environment].nil?
fail 'Target is invalid' if configuration[:environments][@environment][@target].nil?
true
@@ -102,11 +113,13 @@
return unless @environment && @target
configuration[:environments][@environment][@target] = other.deep_merge(configuration[:environments][@environment][@target])
end
def config_files
- Dir.glob(File.join(base_path, FULMAR_CONFIGURATION_DIR, '*.config.yml')).sort
+ 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
end
protected
def lookup_base_path
@@ -137,10 +150,10 @@
end
end
# Loads the configuration from the YAML file and populates all targets
def load_configuration
- @config = { environments: {}, features: {}, hosts: {} }
+ @config = BLANK_CONFIG
config_files.each do |config_file|
@config = @config.deep_merge((YAML.load_file(config_file) || {}).symbolize)
end
# Iterate over all environments and targets to prepare them