class Kitchen::Terraform::ConfigAttributeDefiner
ConfigAttributeDefiner
is the class of objects which define configuration attributes on a plugin class.
Attributes
attribute[RW]
schema[RW]
Public Class Methods
new(attribute:, schema:)
click to toggle source
initialize prepares a new instance of the class.
@param attribute [Kitchen::Terraform::ConfigAttribute] an attribute to be defined on a plugin class. @param schema [Dry::Validation::Schema] a schema to use for validation of values of the attribute. @return [Kitchen::Terraform::ConfigAttributeDefined]
# File lib/kitchen/terraform/config_attribute_definer.rb, line 41 def initialize(attribute:, schema:) self.attribute = attribute.to_sym self.schema = schema end
Public Instance Methods
define(plugin_class:)
click to toggle source
define
defines a configuration attribute on a plugin class.
@param plugin_class [Kitchen::Configurable] a plugin class. @return [self]
# 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).errors.to_h, plugin_class: plugin_class end plugin_class.default_config attribute do |plugin| plugin.send "config_#{attribute}_default_value" end self end
Private Instance Methods
process(messages:, plugin_class:)
click to toggle source
# File lib/kitchen/terraform/config_attribute_definer.rb, line 50 def process(messages:, plugin_class:) return if messages.empty? raise ::Kitchen::UserError, "#{plugin_class} configuration: #{attribute} #{messages}" end