Class: Canon::Config::OverrideResolver
- Inherits:
-
Object
- Object
- Canon::Config::OverrideResolver
- Defined in:
- lib/canon/config/override_resolver.rb
Overview
Resolves configuration values using priority chain Priority: ENV > programmatic > profile > defaults
Instance Attribute Summary collapse
-
#defaults ⇒ Object
readonly
Returns the value of attribute defaults.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#programmatic ⇒ Object
readonly
Returns the value of attribute programmatic.
Instance Method Summary collapse
-
#clear_profile! ⇒ Object
Clear all profile values.
-
#env_set?(key) ⇒ Boolean
Check if value is set by ENV.
-
#initialize(defaults: {}, programmatic: {}, env: {}, profile: {}) ⇒ OverrideResolver
constructor
A new instance of OverrideResolver.
-
#programmatic_set?(key) ⇒ Boolean
Check if value is set programmatically.
-
#resolve(key) ⇒ Object
Resolve a single value using priority chain Uses .key? to properly handle false values.
-
#set_env(key, value) ⇒ Object
Update ENV override.
-
#set_profile(key, value) ⇒ Object
Update profile value.
-
#set_programmatic(key, value) ⇒ Object
Update programmatic value.
-
#source_for(key) ⇒ Object
Get the source of a value.
Constructor Details
#initialize(defaults: {}, programmatic: {}, env: {}, profile: {}) ⇒ OverrideResolver
Returns a new instance of OverrideResolver.
10 11 12 13 14 15 |
# File 'lib/canon/config/override_resolver.rb', line 10 def initialize(defaults: {}, programmatic: {}, env: {}, profile: {}) @defaults = defaults @programmatic = programmatic @env = env @profile = profile end |
Instance Attribute Details
#defaults ⇒ Object (readonly)
Returns the value of attribute defaults.
8 9 10 |
# File 'lib/canon/config/override_resolver.rb', line 8 def defaults @defaults end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
8 9 10 |
# File 'lib/canon/config/override_resolver.rb', line 8 def env @env end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
8 9 10 |
# File 'lib/canon/config/override_resolver.rb', line 8 def profile @profile end |
#programmatic ⇒ Object (readonly)
Returns the value of attribute programmatic.
8 9 10 |
# File 'lib/canon/config/override_resolver.rb', line 8 def programmatic @programmatic end |
Instance Method Details
#clear_profile! ⇒ Object
Clear all profile values
43 44 45 |
# File 'lib/canon/config/override_resolver.rb', line 43 def clear_profile! @profile = {} end |
#env_set?(key) ⇒ Boolean
Check if value is set by ENV
48 49 50 |
# File 'lib/canon/config/override_resolver.rb', line 48 def env_set?(key) @env.key?(key) end |
#programmatic_set?(key) ⇒ Boolean
Check if value is set programmatically
53 54 55 |
# File 'lib/canon/config/override_resolver.rb', line 53 def programmatic_set?(key) @programmatic.key?(key) end |
#resolve(key) ⇒ Object
Resolve a single value using priority chain Uses .key? to properly handle false values
19 20 21 22 23 24 25 |
# File 'lib/canon/config/override_resolver.rb', line 19 def resolve(key) return @env[key] if @env.key?(key) return @programmatic[key] if @programmatic.key?(key) return @profile[key] if @profile.key?(key) @defaults[key] end |
#set_env(key, value) ⇒ Object
Update ENV override
33 34 35 |
# File 'lib/canon/config/override_resolver.rb', line 33 def set_env(key, value) @env[key] = value end |
#set_profile(key, value) ⇒ Object
Update profile value
38 39 40 |
# File 'lib/canon/config/override_resolver.rb', line 38 def set_profile(key, value) @profile[key] = value end |
#set_programmatic(key, value) ⇒ Object
Update programmatic value
28 29 30 |
# File 'lib/canon/config/override_resolver.rb', line 28 def set_programmatic(key, value) @programmatic[key] = value end |
#source_for(key) ⇒ Object
Get the source of a value
58 59 60 61 62 63 64 65 |
# File 'lib/canon/config/override_resolver.rb', line 58 def source_for(key) return :env if @env.key?(key) return :programmatic if @programmatic.key?(key) return :profile if @profile.key?(key) return :default if @defaults.key?(key) nil end |