class Blinkist::Config

Constants

VERSION

Attributes

adapter_type[RW]
app_name[RW]
env[RW]
error_handler[RW]
logger[RW]

Public Class Methods

adapter() click to toggle source
# File lib/blinkist/config.rb, line 54
def adapter
  @adapter ||= Factory.new("Blinkist::Config.adapter_type", Adapters::BUILT_IN).call(adapter_type)
end
get(key, default = nil, scope: nil) click to toggle source
# File lib/blinkist/config.rb, line 20
def get(key, default = nil, scope: nil)
  get!(key, default, scope: scope)
end
get!(key, *args, scope: nil) click to toggle source
# File lib/blinkist/config.rb, line 31
def get!(key, *args, scope: nil)
  # NOTE: we need to do this this way
  # to handle 'nil' default correctly
  case args.length
  when 0
    default = nil
    bang    = true
  when 1
    default = args.first
    bang    = false
  else
    raise ArgumentError, "wrong number of arguments (given #{args.length + 1}, expected 1..2)"
  end

  from_adapter = adapter.get(key, scope: scope)

  if from_adapter.nil? && bang
    handle_error(key, scope)
  else
    return from_adapter || default
  end
end
handle_error(key, scope) click to toggle source
# File lib/blinkist/config.rb, line 58
def handle_error(key, scope)
  handler = Factory.new("Blinkist::Config.error_handler", ErrorHandlers::BUILT_IN).call(error_handler)
  handler.call(key, scope)
end
preload(scope: nil) click to toggle source
# File lib/blinkist/config.rb, line 24
def preload(scope: nil)
  adapter.preload scope: scope
end