Class: UnifiedSettings::Settings
- Inherits:
-
Object
- Object
- UnifiedSettings::Settings
- Defined in:
- lib/unified_settings/settings.rb
Overview
Settings
Main interface for getting any of the settings
Instance Attribute Summary collapse
-
#handlers ⇒ Object
Returns the value of attribute handlers.
Instance Method Summary collapse
- #defined?(key, case_sensitive: nil) ⇒ Boolean
- #get(key, default: NO_DEFAULT, case_sensitive: nil, coerce: true, on_missing_key: nil) ⇒ Object
-
#initialize(handlers: nil) ⇒ Settings
constructor
A new instance of Settings.
Constructor Details
#initialize(handlers: nil) ⇒ Settings
Returns a new instance of Settings.
10 11 12 13 14 15 16 17 18 |
# File 'lib/unified_settings/settings.rb', line 10 def initialize(handlers: nil) handlers_config = handlers || UnifiedSettings.config.handlers @handlers = handlers_config.map { |config| initialize_handler(config) } @coercer = Coercer.new( coercions: UnifiedSettings.config.coercions, coerce_arrays: UnifiedSettings.config.coerce_arrays, array_separator: UnifiedSettings.config.coerce_array_separator ) end |
Instance Attribute Details
#handlers ⇒ Object
Returns the value of attribute handlers.
8 9 10 |
# File 'lib/unified_settings/settings.rb', line 8 def handlers @handlers end |
Instance Method Details
#defined?(key, case_sensitive: nil) ⇒ Boolean
20 21 22 23 24 25 26 27 28 |
# File 'lib/unified_settings/settings.rb', line 20 def defined?(key, case_sensitive: nil) return false unless key @handlers.each do |handler| return true if handler.defined?(key, case_sensitive:) end false end |
#get(key, default: NO_DEFAULT, case_sensitive: nil, coerce: true, on_missing_key: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/unified_settings/settings.rb', line 30 def get( key, default: NO_DEFAULT, case_sensitive: nil, coerce: true, on_missing_key: nil ) return nil unless key @handlers.each do |handler| val = handler.get(key, case_sensitive:) unless val.nil? return coerce ? @coercer.coerce(val) : val end end handle_missing_key(key, default:, on_missing_key:) end |