Module: Kitchen::Terraform::ConfigAttributeCacher
- Included in:
- Kitchen::Terraform::ConfigAttribute::Client, Kitchen::Terraform::ConfigAttribute::PluginDirectory, Kitchen::Terraform::ConfigAttribute::RootModuleDirectory, Kitchen::Terraform::ConfigAttribute::VariableFiles
- Defined in:
- lib/kitchen/terraform/config_attribute_cacher.rb
Overview
Behaviour to cache configuration attribute lookups.
Class Method Summary collapse
-
.extended(configuration_attribute) ⇒ void
A callback to define an attribute lookup cache which is invoked when this module is extended by a configuration attribute.
Instance Method Summary collapse
-
#define_cache(attribute_name: to_sym) ⇒ Object
Defines an instance method named “config_<attribute_name>” which caches the value of the configuration attribute lookup using an equivalently named instance variable.
Class Method Details
.extended(configuration_attribute) ⇒ void
This method returns an undefined value.
A callback to define an attribute lookup cache which is invoked when this module is extended by a configuration attribute.
26 27 28 |
# File 'lib/kitchen/terraform/config_attribute_cacher.rb', line 26 def self.extended(configuration_attribute) configuration_attribute.define_cache end |
Instance Method Details
#define_cache(attribute_name: to_sym) ⇒ Object
Defines an instance method named “config_<attribute_name>” which caches the value of the configuration attribute lookup using an equivalently named instance variable.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kitchen/terraform/config_attribute_cacher.rb', line 34 def define_cache(attribute_name: to_sym) define_method "config_#{attribute_name}" do instance_variable_defined? "@config_#{attribute_name}" and instance_variable_get "@config_#{attribute_name}" or instance_variable_set( "@config_#{attribute_name}", config.fetch(attribute_name) ) end end |