class ConsulApplicationSettings::Providers::LocalStorage

Provides access to settings stored in file system with support of base and local files

Public Class Methods

new(base_path, config) click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 7
def initialize(base_path, config)
  super
  @data = load
end

Public Instance Methods

get(path) click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 12
def get(path)
  get_value_from_hash(absolute_key_path(path), @data)
end

Private Instance Methods

base_file_path() click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 25
def base_file_path
  @config.base_file_path
end
load() click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 18
def load
  base_yml = read_yml(base_file_path)
  local_yml = read_yml(local_file_path)
  DeepMerge.deep_merge!(local_yml, base_yml, preserve_unmergeables: false, overwrite_arrays: true,
                        merge_nil_values: true)
end
local_file_path() click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 29
def local_file_path
  @config.local_file_path
end
read_yml(path) click to toggle source
# File lib/consul_application_settings/providers/local_storage.rb, line 33
def read_yml(path)
  return {} unless File.exist?(path)

  YAML.safe_load(IO.read(path))
rescue Psych::SyntaxError, Errno::ENOENT => e
  raise ConsulApplicationSettings::Error, "Cannot read settings file at #{path}: #{e.message}"
end