Class: PuppetLibrary::Util::ConfigApi::Config
- Inherits:
-
Object
- Object
- PuppetLibrary::Util::ConfigApi::Config
- Defined in:
- lib/puppet_library/util/config_api.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(param) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #set(param, new_value) ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
81 82 83 |
# File 'lib/puppet_library/util/config_api.rb', line 81 def initialize @values = {} end |
Class Method Details
.define_getter(param) ⇒ Object
69 70 71 72 73 |
# File 'lib/puppet_library/util/config_api.rb', line 69 def self.define_getter(param) define_method("get_#{param.name}".to_sym) do get(param) end end |
.define_setter(param) ⇒ Object
75 76 77 78 79 |
# File 'lib/puppet_library/util/config_api.rb', line 75 def self.define_setter(param) define_method(param.name.to_sym) do |new_value| set(param, new_value) end end |
Instance Method Details
#get(param) ⇒ Object
93 94 95 |
# File 'lib/puppet_library/util/config_api.rb', line 93 def get(param) @values[param] end |
#set(param, new_value) ⇒ Object
97 98 99 100 101 |
# File 'lib/puppet_library/util/config_api.rb', line 97 def set(param, new_value) @values[param] = param.process(new_value) rescue => validation_error raise "Invalid value for config parameter '#{param.name}': #{validation_error.} (was expecting #{param.description})" end |
#validate! ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/puppet_library/util/config_api.rb', line 85 def validate! missing_params = params.select { |param| param.required? && @values[param].nil? } unless missing_params.empty? param = missing_params.first raise "Config parameter '#{param.name}' is required (expected #{param.description}), but wasn't specified" end end |