module Kitchen::Terraform::ConfigAttributeCacher
Behaviour to cache configuration attribute lookups.
Public Class Methods
extended(configuration_attribute)
click to toggle source
A callback to define an attribute lookup cache which is invoked when this module is extended by a configuration attribute.
@param configuration_attribute [::Kitchen::Terraform::ConfigAttribute] a configuration attribute. @return [void]
# File lib/kitchen/terraform/config_attribute_cacher.rb, line 26 def self.extended(configuration_attribute) configuration_attribute.define_cache end
Public Instance Methods
define_cache(attribute_name: to_sym)
click to toggle source
Defines an instance method named “config_<attribute_name>” which caches the value of the configuration attribute lookup using an equivalently named instance variable.
@param attribute_name [Symbol] the name of the attribute
# 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