Module: UnifiedSettings
- Includes:
- ActiveSupport::Configurable
- Defined in:
- lib/unified_settings/unified_settings.rb,
lib/unified_settings/coercer.rb,
lib/unified_settings/version.rb,
lib/unified_settings/settings.rb,
lib/unified_settings/handlers/env.rb,
lib/unified_settings/handlers/base.rb,
lib/unified_settings/handlers/constants.rb,
lib/unified_settings/handlers/config_gem.rb,
lib/unified_settings/handlers/credentials.rb
Overview
Unified way to get settings
Defined Under Namespace
Modules: Handlers Classes: Coercer, Settings
Constant Summary collapse
- VERSION =
'0.1.2'
- NO_DEFAULT =
:no_default
Class Method Summary collapse
- .configure ⇒ Object
- .defined?(key, case_sensitive: nil, handlers: nil) ⇒ Boolean
-
.get(key, default: NO_DEFAULT, case_sensitive: nil, handlers: nil, coerce: true, on_missing_key: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Class Method Details
.configure ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/unified_settings/unified_settings.rb', line 11 def self.configure # Set the defaults config.handlers = [ Handlers::Env, Handlers::Credentials, Handlers::Constants ] config.default_value = nil config.case_sensitive = false config.on_missing_key = [:log_error] config.coercions = %i[nil boolean integer float] config.coerce_arrays = true config.coerce_array_separator = ',' super # Create an instance of the settings that can be used @settings = Settings.new end |
.defined?(key, case_sensitive: nil, handlers: nil) ⇒ Boolean
29 30 31 32 |
# File 'lib/unified_settings/unified_settings.rb', line 29 def self.defined?(key, case_sensitive: nil, handlers: nil) settings = handlers.nil? ? @settings : Settings.new(handlers:) settings.defined?(key, case_sensitive:) end |
.get(key, default: NO_DEFAULT, case_sensitive: nil, handlers: nil, coerce: true, on_missing_key: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/unified_settings/unified_settings.rb', line 35 def self.get( key, default: NO_DEFAULT, case_sensitive: nil, handlers: nil, coerce: true, on_missing_key: nil ) settings = handlers.nil? ? @settings : Settings.new(handlers:) settings.get( key, case_sensitive:, coerce:, on_missing_key:, default: ) end |