Class: ConsulApplicationSettings::Reader

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

Overview

Orchestrates fetching values from provider and resolving them

Instance Method Summary collapse

Constructor Details

#initialize(base_path, config) ⇒ Reader

Returns a new instance of Reader.



4
5
6
7
8
9
# 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) }
  @resolvers = config.value_resolvers.map(&:new)
end

Instance Method Details

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



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

def get(path)
  value = fetch_value(path)
  resolve_value(value, path)
end

#load(sub_path) ⇒ Object



18
19
20
21
# File 'lib/consul_application_settings/reader.rb', line 18

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