Class: Triglav::Agent::Base::Setting
- Inherits:
-
Object
- Object
- Triglav::Agent::Base::Setting
- Defined in:
- lib/triglav/agent/base/setting.rb
Overview
A base class represents settings coming from config.yml and cli options
You usually do not need to customize this class, but if you want to implement your original, configure
Triglav::Agent::Configuration.setting_class =
Constant Summary
- DEFAULT_LOG =
'STDOUT'.freeze
- DEFAULT_LOG_LEVEL =
'info'.freeze
- DEFAULT_APP_ENV =
'development'.freeze
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #app_env ⇒ Object
- #config_file ⇒ Object
- #debug? ⇒ Boolean
- #dig(*args) ⇒ Object
- #dotenv? ⇒ Boolean
-
#initialize(cli_options = {}) ⇒ Setting
constructor
A new instance of Setting.
- #log ⇒ Object
- #log_level ⇒ Object
- #logger ⇒ Object
- #reload ⇒ Object
- #serverengine_options ⇒ Object
- #status_file ⇒ Object
- #token_file ⇒ Object
Constructor Details
#initialize(cli_options = {}) ⇒ Setting
Returns a new instance of Setting
21 22 23 24 25 26 27 |
# File 'lib/triglav/agent/base/setting.rb', line 21 def initialize( = {}) @cli_options = if dotenv? require 'dotenv' Dotenv.load end end |
Instance Attribute Details
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options
15 16 17 |
# File 'lib/triglav/agent/base/setting.rb', line 15 def @cli_options end |
Instance Method Details
#[](key) ⇒ Object
86 87 88 |
# File 'lib/triglav/agent/base/setting.rb', line 86 def [](key) config[key] end |
#app_env ⇒ Object
36 37 38 |
# File 'lib/triglav/agent/base/setting.rb', line 36 def app_env @app_env ||= ENV['APP_ENV'] || DEFAULT_APP_ENV end |
#config_file ⇒ Object
40 41 42 |
# File 'lib/triglav/agent/base/setting.rb', line 40 def config_file @cli_options[:config] end |
#debug? ⇒ Boolean
56 57 58 |
# File 'lib/triglav/agent/base/setting.rb', line 56 def debug? @cli_options[:debug] end |
#dig(*args) ⇒ Object
90 91 92 |
# File 'lib/triglav/agent/base/setting.rb', line 90 def dig(*args) config.dig(*args) end |
#dotenv? ⇒ Boolean
52 53 54 |
# File 'lib/triglav/agent/base/setting.rb', line 52 def dotenv? @cli_options[:dotenv] end |
#log ⇒ Object
68 69 70 |
# File 'lib/triglav/agent/base/setting.rb', line 68 def log @cli_options[:log] || config.dig(:serverengine, :log) || DEFAULT_LOG end |
#log_level ⇒ Object
64 65 66 |
# File 'lib/triglav/agent/base/setting.rb', line 64 def log_level @cli_options[:log_level] || config.dig(:serverengine, :log_level) || DEFAULT_LOG_LEVEL end |
#logger ⇒ Object
60 61 62 |
# File 'lib/triglav/agent/base/setting.rb', line 60 def logger @logger ||= Logger.new(log, ) end |
#reload ⇒ Object
29 30 31 32 33 34 |
# File 'lib/triglav/agent/base/setting.rb', line 29 def reload Dotenv.overload if dotenv? @config = nil @logger.close rescue nil @logger = nil end |
#serverengine_options ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/triglav/agent/base/setting.rb', line 72 def = config[:serverengine].dup || {} # serverengine_options[:workers] = 1 # default # serverengine_options[:worker_type] = 'embedded' # default .keys.each do |k| .delete(k) if k.to_s.start_with?('log') end .merge!({ logger: logger, log_level: log_level, setting: self, }) end |
#status_file ⇒ Object
44 45 46 |
# File 'lib/triglav/agent/base/setting.rb', line 44 def status_file @status_file ||= @cli_options[:status] || config.dig(:triglav, :status_file) || 'status.yml' end |
#token_file ⇒ Object
48 49 50 |
# File 'lib/triglav/agent/base/setting.rb', line 48 def token_file @token_file ||= @cli_options[:token] || config.dig(:triglav, :token_file) || 'token.yml' end |