Class: Blinkist::Config
- Inherits:
-
Object
- Object
- Blinkist::Config
- Extended by:
- Gem::Deprecate
- Defined in:
- lib/blinkist/config.rb,
lib/blinkist/config/error.rb,
lib/blinkist/config/factory.rb,
lib/blinkist/config/version.rb,
lib/blinkist/config/adapters.rb,
lib/blinkist/config/error_handlers.rb,
lib/blinkist/config/adapters/adapter.rb,
lib/blinkist/config/value_missing_error.rb,
lib/blinkist/config/adapters/env_adapter.rb,
lib/blinkist/config/not_implemented_error.rb,
lib/blinkist/config/invalid_strategy_error.rb,
lib/blinkist/config/adapters/aws_ssm_adapter.rb,
lib/blinkist/config/adapters/diplomat_adapter.rb,
lib/blinkist/config/error_handlers/error_handler.rb,
lib/blinkist/config/error_handlers/production_only_error_handler.rb
Defined Under Namespace
Modules: Adapters, ErrorHandlers Classes: Adapter, AwsSsmAdapter, DiplomatAdapter, EnvAdapter, Error, ErrorHandler, Factory, InvalidStrategyError, NotImplementedError, ProductionOnlyErrorHandler, ValueMissingError
Constant Summary collapse
- VERSION =
"1.4.0".freeze
Class Attribute Summary collapse
-
.adapter_type ⇒ Object
Returns the value of attribute adapter_type.
-
.app_name ⇒ Object
Returns the value of attribute app_name.
-
.env ⇒ Object
Returns the value of attribute env.
-
.error_handler ⇒ Object
Returns the value of attribute error_handler.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .adapter ⇒ Object
- .get(key, default = nil, scope: nil, refetch: false) ⇒ Object
- .get!(key, *args, scope: nil, refetch: false) ⇒ Object
- .handle_error(key, scope) ⇒ Object
- .preload(scope: nil) ⇒ Object
Class Attribute Details
.adapter_type ⇒ Object
Returns the value of attribute adapter_type.
18 19 20 |
# File 'lib/blinkist/config.rb', line 18 def adapter_type @adapter_type end |
.app_name ⇒ Object
Returns the value of attribute app_name.
18 19 20 |
# File 'lib/blinkist/config.rb', line 18 def app_name @app_name end |
.env ⇒ Object
Returns the value of attribute env.
18 19 20 |
# File 'lib/blinkist/config.rb', line 18 def env @env end |
.error_handler ⇒ Object
Returns the value of attribute error_handler.
18 19 20 |
# File 'lib/blinkist/config.rb', line 18 def error_handler @error_handler end |
.logger ⇒ Object
Returns the value of attribute logger.
18 19 20 |
# File 'lib/blinkist/config.rb', line 18 def logger @logger end |
Class Method Details
.adapter ⇒ Object
54 55 56 |
# 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, refetch: false) ⇒ Object
20 21 22 |
# File 'lib/blinkist/config.rb', line 20 def get(key, default = nil, scope: nil, refetch: false) get!(key, default, scope: scope, refetch: refetch) end |
.get!(key, *args, scope: nil, refetch: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/blinkist/config.rb', line 31 def get!(key, *args, scope: nil, refetch: false) # 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, refetch: refetch) if from_adapter.nil? && bang handle_error(key, scope) else from_adapter || default end end |
.handle_error(key, scope) ⇒ Object
58 59 60 61 |
# 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) ⇒ Object
24 25 26 |
# File 'lib/blinkist/config.rb', line 24 def preload(scope: nil) adapter.preload scope: scope end |