Class: Kitchen::Terraform::ConfigAttributeDefiner

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/terraform/config_attribute_definer.rb

Overview

ConfigAttributeDefiner is the class of objects which define configuration attributes on a plugin class.

Instance Method Summary collapse

Constructor Details

#initialize(attribute:, schema:) ⇒ Kitchen::Terraform::ConfigAttributeDefined

#initialize prepares a new instance of the class.

Parameters:

  • attribute (Kitchen::Terraform::ConfigAttribute)

    an attribute to be defined on a plugin class.

  • schema (Dry::Validation::Schema)

    a schema to use for validation of values of the attribute.



41
42
43
44
# File 'lib/kitchen/terraform/config_attribute_definer.rb', line 41

def initialize(attribute:, schema:)
  self.attribute = attribute.to_sym
  self.schema = schema
end

Instance Method Details

#define(plugin_class:) ⇒ self

#define defines a configuration attribute on a plugin class.

Parameters:

  • plugin_class (Kitchen::Configurable)

    a plugin class.

Returns:

  • (self)


25
26
27
28
29
30
31
32
33
34
# File 'lib/kitchen/terraform/config_attribute_definer.rb', line 25

def define(plugin_class:)
  plugin_class.required_config attribute do |_attribute, value, _plugin|
    process messages: schema.call(value: value).messages, plugin_class: plugin_class
  end
  plugin_class.default_config attribute do |plugin|
    plugin.send "config_#{attribute}_default_value"
  end

  self
end