Class: SparkleFormation::Aws
- Inherits:
-
Object
- Object
- SparkleFormation::Aws
- Extended by:
- Utils::AnimalStrings
- Defined in:
- lib/sparkle_formation/aws.rb
Overview
AWS resource helper
Class Method Summary collapse
-
.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 an AWS 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.
Methods included from Utils::AnimalStrings
Class Method Details
.load(json_path_or_hash) ⇒ TrueClass
Register all discovered resources
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sparkle_formation/aws.rb', line 42 def load(json_path_or_hash) if(json_path_or_hash.is_a?(String)) require 'multi_json' content = AttributeStruct.hashish.new(MultiJson.load(File.read(json))) 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
58 59 60 61 62 |
# File 'lib/sparkle_formation/aws.rb', line 58 def load! require File.join(File.dirname(__FILE__), 'aws', 'cfn_resources.rb') load(AWS_RESOURCES) true end |
.lookup(key) ⇒ Hashish, NilClass
Registry information for given type
85 86 87 |
# File 'lib/sparkle_formation/aws.rb', line 85 def lookup(key) @@registry[registry_key(key)] end |
.register(type, hash) ⇒ TrueClass
Register an AWS resource
16 17 18 19 20 21 22 |
# File 'lib/sparkle_formation/aws.rb', line 16 def register(type, hash) unless(class_variable_defined?(:@@registry)) @@registry = AttributeStruct.hashish.new end @@registry[type] = hash true end |
.registry ⇒ Hashish
Returns currently loaded AWS registry.
90 91 92 93 94 95 96 |
# File 'lib/sparkle_formation/aws.rb', line 90 def registry if(class_variable_defined?(:@@registry)) @@registry else @@registry = AttributeStruct.hashish.new end end |
.registry_key(key) ⇒ String, NilClass
Discover registry key via part searching
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sparkle_formation/aws.rb', line 68 def registry_key(key) key = key.to_s.tr('_', '') @@registry.keys.detect do |ref| ref = ref.downcase snake_parts = ref.split('::') until(snake_parts.empty?) break if snake_parts.join('') == key snake_parts.shift end !snake_parts.empty? end end |
.resource(identifier, key = nil) ⇒ Hashish
Resource information
29 30 31 32 33 34 35 36 |
# File 'lib/sparkle_formation/aws.rb', line 29 def resource(identifier, key=nil) res = lookup(identifier) if(key && res) res[key.to_sym] else res end end |