Class: ConsulApplicationSettings::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/consul_application_settings/reader.rb

Overview

Provides access to settings stored in Consul or in file system

Instance Method Summary collapse

Constructor Details

#initialize(base_path, config) ⇒ Reader

Returns a new instance of Reader.



4
5
6
7
8
# File 'lib/consul_application_settings/reader.rb', line 4

def initialize(base_path, config)
  @base_path = base_path
  @config = config
  @providers = config.settings_providers.map { |provider| provider.new(base_path, config) }
end

Instance Method Details

#get(path) ⇒ Object Also known as: []



10
11
12
13
14
15
16
# File 'lib/consul_application_settings/reader.rb', line 10

def get(path)
  @providers.each do |provider|
    value = provider.get(path)
    return value unless value.nil?
  end
  nil
end

#load(sub_path) ⇒ Object



20
21
22
23
# File 'lib/consul_application_settings/reader.rb', line 20

def load(sub_path)
  new_path = ConsulApplicationSettings::Utils.generate_path(@base_path, sub_path)
  self.class.new(new_path, @config)
end