Module: Kitchen::Pulumi::ConfigAttributeCacher

Overview

Namespace for the config attribute retrieval cache. Allows plugins that include ConfigAttributes to refer to config values by instance variables of the form 'config_'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(config_attribute) ⇒ Object

Defines an attribute cache for a config attribute extending this module


10
11
12
# File 'lib/kitchen/pulumi/config_attribute_cacher.rb', line 10

def self.extended(config_attribute)
  config_attribute.define_cache
end

Instance Method Details

#define_cache(attribute: to_sym) ⇒ Object

Sets an instance variable for a config attribute extending this module


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/kitchen/pulumi/config_attribute_cacher.rb', line 15

def define_cache(attribute: to_sym)
  attr = "config_#{attribute}"

  define_method(attr) do
    if instance_variable_defined?("@#{attr}")
      instance_variable_get("@#{attr}")
    else
      instance_variable_set("@#{attr}", config.fetch(attribute))
    end
  end
end