module InfoHub

Constants

KeyNotFoundError
SettingsAlreadyFinalizedError
SettingsNotFinalizedError
VERSION

Attributes

info_hub_file_paths[RW]

Public Instance Methods

[](key)
Alias for: fetch
fetch(key) click to toggle source
# File lib/info_hub.rb, line 17
def fetch(key)
  settings.fetch(key) { raise_error(key) }
end
Also aliased as: []
finalize!() click to toggle source
# File lib/info_hub.rb, line 30
def finalize!
  raise SettingsAlreadyFinalizedError, 'InfoHub configuration is already finalized.' if finalized?

  info_hub_file_paths.freeze
end
finalized?() click to toggle source
# File lib/info_hub.rb, line 36
def finalized?
  info_hub_file_paths.frozen?
end
get(*keys) click to toggle source
# File lib/info_hub.rb, line 26
def get(*keys)
  keys.inject(settings) { |settings, key| settings.fetch(key) { raise_error(key) } }
end
use(key) { |fetch(key)| ... } click to toggle source
# File lib/info_hub.rb, line 22
def use(key)
  yield fetch(key)
end

Private Instance Methods

raise_error(key) click to toggle source
# File lib/info_hub.rb, line 52
def raise_error(key)
  raise KeyNotFoundError, "`#{key}` key not found"
end
settings() click to toggle source
# File lib/info_hub.rb, line 42
def settings
  @settings ||= begin
    raise SettingsNotFinalizedError, 'Settings not finalized' unless finalized?

    info_hub_file_paths.inject({}) do |settings, path|
      settings.deep_merge!(YAML.load_file(path).deep_symbolize_keys)
    end
  end
end