Class: DVLA::Kaping::Config
- Inherits:
-
Object
- Object
- DVLA::Kaping::Config
- Defined in:
- lib/dvla/kaping/config.rb
Constant Summary collapse
- ATTRIBUTES =
%w[host index result_size log_level].freeze
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#yaml ⇒ Object
Returns the value of attribute yaml.
-
#yaml_override_path ⇒ Object
Returns the value of attribute yaml_override_path.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_yaml(path) ⇒ Object
step 1 - find kaping.yml.
- #log_level(_log_level = @yaml.dig(:kaping, :log_level)) ⇒ Object
- #merge_yaml(path) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/dvla/kaping/config.rb', line 16 def initialize @yaml = load_yaml(Dir["#{Dir.pwd}/**/kaping.yml"].first) ATTRIBUTES.each do |attr| instance_variable_set(:"@#{attr}", ENV.fetch(attr.to_s.upcase, nil)) end @logger = Logger.new($stdout) @log_level ||= 'INFO' @result_size ||= 100 end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
11 12 13 |
# File 'lib/dvla/kaping/config.rb', line 11 def logger @logger end |
#yaml ⇒ Object
Returns the value of attribute yaml.
10 11 12 |
# File 'lib/dvla/kaping/config.rb', line 10 def yaml @yaml end |
#yaml_override_path ⇒ Object
Returns the value of attribute yaml_override_path.
11 12 13 |
# File 'lib/dvla/kaping/config.rb', line 11 def yaml_override_path @yaml_override_path end |
Instance Method Details
#load_yaml(path) ⇒ Object
step 1 - find kaping.yml
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dvla/kaping/config.rb', line 29 def load_yaml(path) path = "#{path}.yml" unless %w[.yaml .yml].include?(File.extname(path)) if File.exist?(path) YAML.safe_load(ERB.new(File.read(path)).result, symbolize_names: true, aliases: true) else warn("[WARN] YAML file not found at: '#{path}'") nil end end |
#log_level(_log_level = @yaml.dig(:kaping, :log_level)) ⇒ Object
63 64 65 |
# File 'lib/dvla/kaping/config.rb', line 63 def log_level(_log_level = @yaml.dig(:kaping, :log_level)) @log end |
#merge_yaml(path) ⇒ Object
48 49 50 51 52 |
# File 'lib/dvla/kaping/config.rb', line 48 def merge_yaml(path) config = load_yaml(path) @yaml = @yaml.deep_merge(config) unless config.nil? end |