Class: Jets::Resource

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/jets/resource/base.rb,
lib/jets/resource.rb,
lib/jets/resource/replacer.rb,
lib/jets/resource/associated.rb,
lib/jets/resource/permission.rb,
lib/jets/resource/standardizer.rb

Overview

Does not do full expansion, mainly a container that holds the definition and standardizes it without camelizing it.

Defined Under Namespace

Modules: ApiGateway, ChildStack, Config, Events, Iam, Iot, Lambda, Logs, Route53, S3, Sns, Sqs Classes: Associated, Base, Permission, Replacer, Standardizer

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, replacements = {}) ⇒ Resource

Returns a new instance of Resource.



5
6
7
8
# File 'lib/jets/resource.rb', line 5

def initialize(definition, replacements={})
  @definition = definition
  @replacements = replacements
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



4
5
6
# File 'lib/jets/resource.rb', line 4

def definition
  @definition
end

#replacementsObject (readonly)

Returns the value of attribute replacements.



4
5
6
# File 'lib/jets/resource.rb', line 4

def replacements
  @replacements
end

Class Method Details

.truncate_id(id, postfix = '') ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/jets/resource.rb', line 29

def self.truncate_id(id, postfix = '')
  # Api Gateway resource name has a limit of 64 characters.
  # Yet it throws not found when ID is longer than 62 characters and I don't know why.
  # To keep it safe, let's stick to the 62 characters limit.
  if id.size + postfix.size > 62
    "#{id[0..(55 - postfix.size)]}#{Digest::MD5.hexdigest(id)[0..5]}#{postfix}"
  else
    "#{id}#{postfix}"
  end
end

Instance Method Details

#attributesObject



48
49
50
51
52
# File 'lib/jets/resource.rb', line 48

def attributes
  attributes = template.values.first
  attributes = replacer.replace_placeholders(attributes)
  Jets::Camelizer.transform(attributes)
end

#logical_idObject



20
21
22
23
24
25
26
27
# File 'lib/jets/resource.rb', line 20

def logical_id
  id = template.keys.first
  # replace possible {namespace} in the logical id
  id = replacer.replace_value(id)
  id = Jets::Camelizer.camelize(id)

  Jets::Resource.truncate_id(id)
end

#outputsObject



58
59
60
# File 'lib/jets/resource.rb', line 58

def outputs
  {}
end

#parametersObject



54
55
56
# File 'lib/jets/resource.rb', line 54

def parameters
  {}
end

#permissionObject



67
68
69
# File 'lib/jets/resource.rb', line 67

def permission
  Permission.new(replacements, self)
end

#propertiesObject



44
45
46
# File 'lib/jets/resource.rb', line 44

def properties
  attributes['Properties']
end

#replacerObject



62
63
64
# File 'lib/jets/resource.rb', line 62

def replacer
  Replacer.new(replacements)
end

#standarize(*definition) ⇒ Object

CloudFormation Resources reference: amzn.to/2NKg6ip



16
17
18
# File 'lib/jets/resource.rb', line 16

def standarize(*definition)
  Standardizer.new(definition).template
end

#templateObject



10
11
12
# File 'lib/jets/resource.rb', line 10

def template
  standarize(definition)
end

#typeObject



40
41
42
# File 'lib/jets/resource.rb', line 40

def type
  attributes['Type']
end