Class: SparkleFormation::Aws

Inherits:
Object
  • Object
show all
Extended by:
Utils::AnimalStrings
Defined in:
lib/sparkle_formation/aws.rb

Overview

AWS resource helper

Class Method Summary collapse

Methods included from Utils::AnimalStrings

camel, snake

Class Method Details

.load(json_path_or_hash) ⇒ TrueClass

Register all discovered resources

Parameters:

  • json_path_or_hash (String, Hashish)

    path to files or hash

Returns:

  • (TrueClass)


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

Returns:

  • (TrueClass)


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

Parameters:

  • key (String, Symbol)

Returns:

  • (Hashish, NilClass)


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

Parameters:

  • type (String)

    AWS CFN resource type

  • hash (Hash)

    metadata information

Returns:

  • (TrueClass)


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

.registryHashish

Returns currently loaded AWS registry.

Returns:

  • (Hashish)

    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

Parameters:

  • key (String, Symbol)

Returns:

  • (String, NilClass)


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

Parameters:

  • identifier (String, Symbol)

    resource identifier

  • key (String, Symbol) (defaults to: nil)

    specific data

Returns:

  • (Hashish)


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