Module: Kitchen::Terraform::ConfigAttributeCacher

Overview

Behaviour to cache configuration attribute lookups.

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:



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.

Parameters:

  • attribute_name (Symbol) (defaults to: to_sym)

    the name of the attribute



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