Module: Kitchen::Configurable::ClassMethods
- Defined in:
- lib/kitchen/configurable.rb
Overview
Class methods which will be mixed in on inclusion of Configurable module.
Instance Method Summary collapse
-
#default_config(attr, value = nil) {|object| ... } ⇒ Object
Sets a sane default value for a configuration attribute.
-
#defaults ⇒ Hash
private
A hash of attribute keys and default values which has been merged with any superclass defaults.
-
#deprecate_config_for(attr, value = nil) {|object| ... } ⇒ Object
Set the appropriate deprecation message for a given attribute name.
- #deprecated_attributes ⇒ Object
-
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
-
#expand_path_for(attr, value = true) {|object| ... } ⇒ Object
Ensures that an attribute which is a path will be fully expanded at the right time.
-
#expanded_paths ⇒ Hash
private
A hash of attribute keys and truthy/falsey values to determine if said attribute needs to be fully file path expanded, which has been merged with any superclass expanded paths.
-
#plugin_version(version) ⇒ Object
Sets the loaded version of this plugin, usually corresponding to the RubyGems version of the plugin’s library.
-
#required_config(attr) {|attr, value, object| ... } ⇒ Object
Ensures that an attribute must have a non-nil, non-empty String value.
-
#super_defaults ⇒ Hash
private
A hash of defaults from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
- #super_deprecated_attributes ⇒ Object
-
#super_expanded_paths ⇒ Hash
private
A hash of expanded paths from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
-
#super_validations ⇒ Hash
private
A hash of validations from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
-
#validations ⇒ Hash
private
A hash of attribute keys and valudation callable blocks which has been merged with any superclass valudations.
Instance Method Details
#default_config(attr, value = nil) {|object| ... } ⇒ Object
Sets a sane default value for a configuration attribute. These values can be overridden by provided configuration or in a subclass with another default_config declaration.
463 464 465 |
# File 'lib/kitchen/configurable.rb', line 463 def default_config(attr, value = nil, &block) defaults[attr] = block_given? ? block : value end |
#defaults ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of attribute keys and default values which has been merged with any superclass defaults.
552 553 554 |
# File 'lib/kitchen/configurable.rb', line 552 def defaults @defaults ||= {}.merge(super_defaults) end |
#deprecate_config_for(attr, value = nil) {|object| ... } ⇒ Object
Set the appropriate deprecation message for a given attribute name
513 514 515 |
# File 'lib/kitchen/configurable.rb', line 513 def deprecate_config_for(attr, value = nil, &block) deprecated_attributes[attr] = block_given? ? block : value end |
#deprecated_attributes ⇒ Object
586 587 588 |
# File 'lib/kitchen/configurable.rb', line 586 def deprecated_attributes @deprecated_attributes ||= {}.merge(super_deprecated_attributes) end |
#diagnose ⇒ Hash
Returns a Hash of configuration and other useful diagnostic information.
433 434 435 436 437 438 439 |
# File 'lib/kitchen/configurable.rb', line 433 def diagnose { class: name, version: @plugin_version ||= nil, api_version: @api_version ||= nil, } end |
#expand_path_for(attr, value = true) {|object| ... } ⇒ Object
Ensures that an attribute which is a path will be fully expanded at the right time. This helps make the configuration unambiguous and much easier to debug and diagnose.
Note that the file path expansion is only intended for paths on the local workstation invking the Test Kitchen code.
493 494 495 |
# File 'lib/kitchen/configurable.rb', line 493 def (attr, value = true, &block) [attr] = block_given? ? block : value end |
#expanded_paths ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of attribute keys and truthy/falsey values to determine if said attribute needs to be fully file path expanded, which has been merged with any superclass expanded paths.
571 572 573 |
# File 'lib/kitchen/configurable.rb', line 571 def @expanded_paths ||= {}.merge() end |
#plugin_version(version) ⇒ Object
Sets the loaded version of this plugin, usually corresponding to the RubyGems version of the plugin’s library. If the plugin does not set this value, then ‘nil` will be used and reported.
425 426 427 |
# File 'lib/kitchen/configurable.rb', line 425 def plugin_version(version) # rubocop:disable Style/TrivialAccessors @plugin_version = version end |
#required_config(attr) {|attr, value, object| ... } ⇒ Object
Ensures that an attribute must have a non-nil, non-empty String value. The default behavior will be to raise a user error and thereby halting further configuration processing. Good use cases for require_config might be cloud provider credential keys and other similar data.
536 537 538 539 540 541 542 543 544 545 546 547 |
# File 'lib/kitchen/configurable.rb', line 536 def required_config(attr, &block) unless block_given? klass = self block = lambda do |_, value, thing| if value.nil? || value.to_s.empty? attribute = "#{klass}#{thing.instance.to_str}#config[:#{attr}]" raise UserError, "#{attribute} cannot be blank" end end end validations[attr] = block end |
#super_defaults ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of defaults from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
559 560 561 562 563 564 565 |
# File 'lib/kitchen/configurable.rb', line 559 def super_defaults if superclass.respond_to?(:defaults) superclass.defaults else {} end end |
#super_deprecated_attributes ⇒ Object
590 591 592 593 594 595 596 |
# File 'lib/kitchen/configurable.rb', line 590 def super_deprecated_attributes if superclass.respond_to?(:deprecated_attributes) superclass.deprecated_attributes else {} end end |
#super_expanded_paths ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of expanded paths from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
578 579 580 581 582 583 584 |
# File 'lib/kitchen/configurable.rb', line 578 def if superclass.respond_to?(:expanded_paths) superclass. else {} end end |
#super_validations ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of validations from the included class’ superclass if defined in the superclass, or an empty hash otherwise.
608 609 610 611 612 613 614 |
# File 'lib/kitchen/configurable.rb', line 608 def super_validations if superclass.respond_to?(:validations) superclass.validations else {} end end |
#validations ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a hash of attribute keys and valudation callable blocks which has been merged with any superclass valudations.
601 602 603 |
# File 'lib/kitchen/configurable.rb', line 601 def validations @validations ||= {}.merge(super_validations) end |