class SparkleFormation::Resources
Resources
helper
Resources
helper
Resources
helper
Resources
helper
Resources
helper
Resources
helper
Resources
helper
Constants
- PROPERTY_UPDATE_CONDITIONALS
Property
update conditionals Format: Smash.new(RESOURCE_TYPE => {PROPERTY_NAME => [PropertyConditional]})- Property
Defines a resource property
@param name [String] property name @param description [String] property descrition @param type [String] property data type @param required [TrueClass, FalseClass] property is required @param update_causes [String] one of: 'replacement', 'interrupt', 'unknown', 'none' @param conditionals [Array<UpdateCausesConditional>] conditionals for update causes
- RESOURCE_TYPE_NAMESPACE_SPLITTER
String to split for resource namespacing
- RESOURCE_TYPE_TR
Characters to be removed from supplied key on matching
- Resource
Defines a resource type
@param name [String] name of resource type @param properties [Array<Property>] resource properties @param raw [Hash] raw resource information
- UpdateCausesConditional
Defines conditional result for cause of property update
@param update_causes [String] one of: 'replacement', 'interrupt', 'unknown', 'none' @param conditional [Proc, TrueClass] condition logic. passed two values: Hash of resource “final” state and
Hash of resource "original" state
Public Class Methods
@return [String] base registry key
# File lib/sparkle_formation/resources.rb, line 81 def base_key Bogo::Utility.snake(self.name.split("::").last) # rubocop:disable Style/RedundantSelf end
Called before key lookup to perform any required actions for customized setup/modifications
# File lib/sparkle_formation/resources.rb, line 190 def key_loader(key) true end
Register all discovered resources
@param json_path_or_hash [String, Hashish] path to files or hash @return [TrueClass]
# File lib/sparkle_formation/resources.rb, line 120 def load(json_path_or_hash) case json_path_or_hash when String content = AttributeStruct.hashish.new(MultiJson.load(File.read(json_path_or_hash))) when Hash content = json_path_or_hash else raise TypeError.new("Expecting `String` or `Hash` type but received `#{json_path_or_hash.class}`") end content.each do |type, hash| register(type, hash) end true end
Load the builtin AWS resources
@return [TrueClass]
# File lib/sparkle_formation/resources.rb, line 138 def load! true end
Registry
information for given type
@param key [String, Symbol] @return [Hashish, NilClass]
# File lib/sparkle_formation/resources.rb, line 198 def lookup(key) @@registry[base_key][key] || @@registry[base_key][registry_key(key)] end
Register resource
@param type [String] Orchestration resource type @param hash [Hash] metadata information @return [TrueClass]
# File lib/sparkle_formation/resources.rb, line 90 def register(type, hash) unless hash.is_a?(Hash) raise TypeError.new("Expecting `Hash` type but received `#{hash.class}`") end unless class_variable_defined?(:@@registry) @@registry = AttributeStruct.hashish.new end @@registry[base_key] ||= AttributeStruct.hashish.new @@registry[base_key][type.to_s] = hash true end
@return [Hashish] currently loaded AWS registry
# File lib/sparkle_formation/resources.rb, line 203 def registry unless class_variable_defined?(:@@registry) @@registry = AttributeStruct.hashish.new end @@registry[base_key] end
Discover registry key via part searching
@param key [String, Symbol] @return [String, NilClass]
# File lib/sparkle_formation/resources.rb, line 146 def registry_key(key) key_loader(key) if registry[key] result = key else o_key = key key = key.to_s.downcase.tr(self.const_get(:RESOURCE_TYPE_TR), "") # rubocop:disable Style/RedundantSelf snake_parts = nil result = @@registry[base_key].keys.detect do |ref| ref = ref.downcase snake_parts = ref.split(resource_type_splitter) until snake_parts.empty? break if snake_parts.join("") == key snake_parts.shift end !snake_parts.empty? end if result collisions = @@registry[base_key].keys.find_all do |ref| split_ref = ref.downcase.split(resource_type_splitter) ref = Array(split_ref.slice(split_ref.size - snake_parts.size, split_ref.size)).join("") key == ref end if collisions.size > 1 raise ArgumentError.new "Ambiguous dynamic name returned multiple matches! " \ "`#{o_key.inspect}` -> #{collisions.sort.join(", ")}" end end end result end
Resource
information
@param identifier [String, Symbol] resource identifier @param key [String, Symbol] specific data @return [Hashish, NilClass]
# File lib/sparkle_formation/resources.rb, line 107 def resource(identifier, key = nil) res = lookup(identifier) if key && res res[key.to_sym] else res end end
Simple hook method to allow resource customization if the specific provider requires/offers extra setup
@param struct [SparkleStruct] @param lookup_key [String] @return [SparkleStruct]
# File lib/sparkle_formation/resources.rb, line 216 def resource_customizer(struct, lookup_key) struct end
Information about specific resource type
@param type [String] resource type @return [Resource]
# File lib/sparkle_formation/resources.rb, line 224 def resource_lookup(type) result = registry[type] if result properties = result.fetch("full_properties", {}).map do |p_name, p_info| Property.new(p_name, p_info[:description], p_info[:type], p_info[:required], p_info[:update_causes], self.const_get(:PROPERTY_UPDATE_CONDITIONALS).get(type, p_name)) end Resource.new(type, properties, result) else raise KeyError.new "Failed to locate requested resource type: `#{type}`" end end
@return [Regexp] value for resource splitting rubocop:disable Style/RedundantSelf
# File lib/sparkle_formation/resources.rb, line 180 def resource_type_splitter Regexp.new( [self.const_get(:RESOURCE_TYPE_NAMESPACE_SPLITTER)].flatten.compact.map { |value| Regexp.escape(value) }.join("|") ) end