Class: SparkleFormation::Resources
- Inherits:
-
Object
- Object
- SparkleFormation::Resources
- Extended by:
- Utils::AnimalStrings
- Defined in:
- lib/sparkle_formation/resources.rb,
lib/sparkle_formation/resources/aws.rb,
lib/sparkle_formation/resources/heat.rb,
lib/sparkle_formation/resources/azure.rb,
lib/sparkle_formation/resources/rackspace.rb
Overview
Resources helper
Defined Under Namespace
Classes: Aws, Azure, Heat, Rackspace
Constant Summary collapse
- RESOURCE_TYPE_TR =
Characters to be removed from supplied key on matching
'_'- RESOURCE_TYPE_NAMESPACE_SPLITTER =
String to split for resource namespacing
'::'
Class Method Summary collapse
-
.base_key ⇒ String
Base registry key.
-
.load(json_path_or_hash) ⇒ TrueClass
Register all discovered resources.
-
.load! ⇒ TrueClass
Load the builtin AWS resources.
-
.lookup(key) ⇒ Hashish, NilClass
Registry information for given type.
-
.register(type, hash) ⇒ TrueClass
Register resource.
-
.registry ⇒ Hashish
Currently loaded AWS registry.
-
.registry_key(key) ⇒ String, NilClass
Discover registry key via part searching.
-
.resource(identifier, key = nil) ⇒ Hashish
Resource information.
-
.resource_customizer(struct, lookup_key) ⇒ SparkleStruct
Simple hook method to allow resource customization if the specific provider requires/offers extra setup.
-
.resource_type_splitter ⇒ Regexp
rubocop:disable Style/RedundantSelf.
Methods included from Utils::AnimalStrings
Class Method Details
.base_key ⇒ String
Returns base registry key.
23 24 25 |
# File 'lib/sparkle_formation/resources.rb', line 23 def base_key Bogo::Utility.snake(self.name.split('::').last) # rubocop:disable Style/RedundantSelf end |
.load(json_path_or_hash) ⇒ TrueClass
Register all discovered resources
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sparkle_formation/resources.rb', line 59 def load(json_path_or_hash) if(json_path_or_hash.is_a?(String)) content = AttributeStruct.hashish.new(MultiJson.load(File.read(json_path_or_hash))) else content = json_path_or_hash end content.each do |type, hash| register(type, hash) end true end |
.load! ⇒ TrueClass
Load the builtin AWS resources
74 75 76 |
# File 'lib/sparkle_formation/resources.rb', line 74 def load! true end |
.lookup(key) ⇒ Hashish, NilClass
Registry information for given type
123 124 125 |
# File 'lib/sparkle_formation/resources.rb', line 123 def lookup(key) @@registry[base_key][registry_key(key)] end |
.register(type, hash) ⇒ TrueClass
Register resource
32 33 34 35 36 37 38 39 |
# File 'lib/sparkle_formation/resources.rb', line 32 def register(type, hash) unless(class_variable_defined?(:@@registry)) @@registry = AttributeStruct.hashish.new end @@registry[base_key] ||= AttributeStruct.hashish.new @@registry[base_key][type] = hash true end |
.registry ⇒ Hashish
Returns currently loaded AWS registry.
128 129 130 131 132 133 |
# File 'lib/sparkle_formation/resources.rb', line 128 def registry unless(class_variable_defined?(:@@registry)) @@registry = AttributeStruct.hashish.new end @@registry[base_key] end |
.registry_key(key) ⇒ String, NilClass
Discover registry key via part searching
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/sparkle_formation/resources.rb', line 82 def registry_key(key) o_key = key key = key.to_s.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 = 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 result end |
.resource(identifier, key = nil) ⇒ Hashish
Resource information
46 47 48 49 50 51 52 53 |
# File 'lib/sparkle_formation/resources.rb', line 46 def resource(identifier, key=nil) res = lookup(identifier) if(key && res) res[key.to_sym] else res end end |
.resource_customizer(struct, lookup_key) ⇒ SparkleStruct
Simple hook method to allow resource customization if the specific provider requires/offers extra setup
141 142 143 |
# File 'lib/sparkle_formation/resources.rb', line 141 def resource_customizer(struct, lookup_key) struct end |
.resource_type_splitter ⇒ Regexp
rubocop:disable Style/RedundantSelf
111 112 113 114 115 116 117 |
# File 'lib/sparkle_formation/resources.rb', line 111 def resource_type_splitter Regexp.new( [self.const_get(:RESOURCE_TYPE_NAMESPACE_SPLITTER)].flatten.compact.map{|value| Regexp.escape(value) }.join('|') ) end |