Class: R10K::Settings::Container
- Inherits:
-
Object
- Object
- R10K::Settings::Container
- Defined in:
- lib/r10k/settings/container.rb
Overview
if those options aren’t set on the given container.
Defined Under Namespace
Classes: InvalidKey
Instance Attribute Summary collapse
-
#valid_keys ⇒ Set<Symbol>
All valid keys defined on the container or parent container.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Look up a value in the container.
-
#[]=(key, value) ⇒ Object
Set a value on the container.
-
#add_valid_key(key) ⇒ void
Define a valid container key.
-
#initialize(parent = nil) ⇒ Container
constructor
A new instance of Container.
-
#reset! ⇒ void
Clear all existing settings in this container.
-
#valid_key?(key) ⇒ true, false
Determine if a key is a valid setting.
Constructor Details
#initialize(parent = nil) ⇒ Container
Returns a new instance of Container.
14 15 16 17 18 19 |
# File 'lib/r10k/settings/container.rb', line 14 def initialize(parent = nil) @parent = parent @valid_keys = Set.new @settings = {} end |
Instance Attribute Details
#valid_keys ⇒ Set<Symbol>
Returns All valid keys defined on the container or parent container.
11 12 13 |
# File 'lib/r10k/settings/container.rb', line 11 def valid_keys @valid_keys end |
Instance Method Details
#[](key) ⇒ Object?
Look up a value in the container. The lookup checks the current container, and then falls back to the parent container if it’s given.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/r10k/settings/container.rb', line 30 def [](key) validate_key! key if @settings[key] @settings[key] elsif @parent && (pkey = @parent[key]) begin @settings[key] = pkey.dup rescue TypeError @settings[key] = pkey end @settings[key] end end |
#[]=(key, value) ⇒ Object
Set a value on the container
52 53 54 55 56 |
# File 'lib/r10k/settings/container.rb', line 52 def []=(key, value) validate_key! key @settings[key] = value end |
#add_valid_key(key) ⇒ void
This should only be used by R10K::Settings::Container#R10K#R10K::Settings#R10K::Settings::ClassSettings
This method returns an undefined value.
Define a valid container key
64 65 66 |
# File 'lib/r10k/settings/container.rb', line 64 def add_valid_key(key) @valid_keys.add(key) end |
#reset! ⇒ void
This method returns an undefined value.
Clear all existing settings in this container. Valid settings are left alone.
84 85 86 |
# File 'lib/r10k/settings/container.rb', line 84 def reset! @settings = {} end |
#valid_key?(key) ⇒ true, false
Determine if a key is a valid setting.
73 74 75 76 77 78 79 80 |
# File 'lib/r10k/settings/container.rb', line 73 def valid_key?(key) if @valid_keys.include?(key) true elsif @parent and @parent.valid_key?(key) @valid_keys.add(key) true end end |