class Fulmar::Domain::Service::ConfigurationService

Loads and prepares the configuration from the yaml file TODO: Clone target configuration when used as a parameter to another service so an environment change won't affect it Not Sure if that is actually a god idea

Constants

BLANK_CONFIG
DEPLOYMENT_CONFIG_FILE
FULMAR_CONFIGURATION
FULMAR_CONFIGURATION_DIR
FULMAR_FILE

Attributes

debug[RW]
environment[R]
load_user_config[RW]
target[R]

Public Class Methods

new() click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 31
def initialize
  @load_user_config = true
end

Public Instance Methods

base_path() click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 35
def base_path
  @base_path ||= lookup_base_path
end
config_files() click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 52
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") && @load_user_config
  files
end
configuration() click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 39
def configuration
  @config ||= load_configuration
end
merge(other) click to toggle source

Merge another configuration into the currently active one Useful for supplying a default configuration, as values are not overwritten. Hashes are merged. @param [Hash] other

# File lib/fulmar/domain/service/configuration_service.rb, line 47
def merge(other)
  return unless @environment && @target
  configuration[:environments][@environment][@target] = other.deep_merge(configuration[:environments][@environment][@target])
end
reset() click to toggle source

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

# File lib/fulmar/domain/service/configuration_service.rb, line 61
def reset
  @config = nil
end

Protected Instance Methods

check_version(version) click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 99
def check_version(version)
  return if version.nil?
  unless  Gem::Dependency.new('', version).match?('', Fulmar::VERSION)
    fail "Project requires another version of fulmar: #{version}"
  end
end
load_configuration() click to toggle source

Loads the configuration from the YAML file and populates all targets

# File lib/fulmar/domain/service/configuration_service.rb, line 79
def load_configuration
  config = BLANK_CONFIG
  config_files.each do |config_file|
    config = config.deep_merge((YAML.load_file(config_file) || {}).deep_symbolize_keys)
  end
  check_version(config[:project][:fulmar_version])
  Fulmar::Domain::Model::Configuration.new(config, base_path, @debug)
end
lookup_base_path() click to toggle source
# File lib/fulmar/domain/service/configuration_service.rb, line 67
def lookup_base_path
  fulmar_file = Fulmar::Service::HelperService.reverse_file_lookup(Dir.pwd, FULMAR_FILE)

  unless fulmar_file
    puts 'Fulmar setup not found. Please run "fulmar setup" to initialize the application in the current directory.'
    exit
  end

  File.dirname(fulmar_file)
end
prepare_dependencies() click to toggle source

@todo Move to configuration model if I know what this was or if it is relevant

# File lib/fulmar/domain/service/configuration_service.rb, line 89
def prepare_dependencies
  @config[:dependencies].each_pair do |_env, repos|
    repos.each_pair do |_name, repo|
      next if repo[:path].blank?
      full_path = File.expand_path("#{base_path}/#{repo[:path]}")
      repo[:path] = full_path unless repo[:path][0,1] == '/'
    end
  end
end