lib/legion/settings/loader.rb in legion-settings-0.1.1 vs lib/legion/settings/loader.rb in legion-settings-0.2.0
- old
+ new
@@ -1,15 +1,16 @@
+require 'socket'
+
module Legion
module Settings
- # This is the main settings class, needs refactor
class Loader
- # This is the standard error
class Error < RuntimeError; end
attr_reader :warnings
attr_reader :errors
attr_reader :loaded_files
+ attr_reader :settings
def initialize
@warnings = []
@errors = []
@settings = default_settings
@@ -18,47 +19,39 @@
self.class.create_category_methods
end
def client_defaults
{
- name: system_hostname,
- address: system_address
+ hostname: system_hostname,
+ address: system_address,
+ name: "#{::Socket.gethostname.gsub('.', '_')}.#{::Process.pid}"
}
end
- def default_settings # rubocop:disable Metrics/MethodLength
- default = {
- client: {},
- legion: {
- spawn: {
- limit: 12
- },
- extensions: {}
+ def default_settings
+ {
+ client: client_defaults,
+ cluster: { public_keys: {} },
+ crypt: {
+ cluster_secret: nil,
+ cluster_secret_timeout: 5,
+ vault: { connected: false }
},
- transport: {
- rabbitmq: {
- user: 'guest',
- password: 'guest',
- host: '127.0.0.1'
- }
+ cache: { enabled: true, connected: false, driver: 'dalli' },
+ extensions: {},
+ default_extension_settings: {
+ logger: { level: 'info', trace: false, extended: false }
},
- data: {
- mysql: {
- user: 'legion',
- password: 'legion',
- max_connections: 20,
- database: 'legion',
- host: '127.0.0.1',
- debug: false
- },
- models: {},
- connection: {},
- migrations: { continue_on_fail: false }
- }
+ logging: {
+ level: 'debug',
+ location: 'stdout',
+ trace: true,
+ backtrace_logging: true
+ },
+ transport: { connected: false },
+ data: { connected: false }
}
- default[:client] = client_defaults if %w[client rspec].include?(legion_service_name)
- default
end
def self.create_category_methods
# CATEGORIES.each do |category|
# define_method(category) do
@@ -99,9 +92,15 @@
end
end
def load_env
load_api_env
+ end
+
+ def load_module_default(config)
+ merged = deep_merge(@settings, config)
+ deep_diff(@settings, merged) unless @loaded_files.empty?
+ @settings = merged
end
def load_file(file) # rubocop:disable Metrics/AbcSize
Legion::Logging.debug("Trying to load file #{file}")
if File.file?(file) && File.readable?(file)