Class: Fulmar::Domain::Service::ConfigurationService

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fulmar/domain/service/configuration_service.rb

Overview

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

Constant Summary collapse

FULMAR_FILE =
'Fulmarfile'
FULMAR_CONFIGURATION =
'FulmarConfiguration'
FULMAR_CONFIGURATION_DIR =
'Fulmar'
DEPLOYMENT_CONFIG_FILE =
'deployment.yml'
BLANK_CONFIG =
{
  project: {},
  environments: {},
  features: {},
  hosts: {},
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfigurationService

Returns a new instance of ConfigurationService.



31
32
33
# File 'lib/fulmar/domain/service/configuration_service.rb', line 31

def initialize
  @load_user_config = true
end

Instance Attribute Details

#debugObject

Returns the value of attribute debug.



29
30
31
# File 'lib/fulmar/domain/service/configuration_service.rb', line 29

def debug
  @debug
end

#environmentObject (readonly)

Returns the value of attribute environment.



28
29
30
# File 'lib/fulmar/domain/service/configuration_service.rb', line 28

def environment
  @environment
end

#load_user_configObject

Returns the value of attribute load_user_config.



29
30
31
# File 'lib/fulmar/domain/service/configuration_service.rb', line 29

def load_user_config
  @load_user_config
end

#targetObject (readonly)

Returns the value of attribute target.



28
29
30
# File 'lib/fulmar/domain/service/configuration_service.rb', line 28

def target
  @target
end

Instance Method Details

#base_pathObject



35
36
37
# File 'lib/fulmar/domain/service/configuration_service.rb', line 35

def base_path
  @base_path ||= lookup_base_path
end

#config_filesObject



52
53
54
55
56
# 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

#configurationObject



39
40
41
# File 'lib/fulmar/domain/service/configuration_service.rb', line 39

def configuration
  @config ||= load_configuration
end

#merge(other) ⇒ Object

Merge another configuration into the currently active one Useful for supplying a default configuration, as values are not overwritten. Hashes are merged.

Parameters:

  • other (Hash)


47
48
49
50
# 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

#resetObject

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



61
62
63
# File 'lib/fulmar/domain/service/configuration_service.rb', line 61

def reset
  @config = nil
end