Class: MkStack::Section

Inherits:
Object
  • Object
show all
Defined in:
lib/mkstack/section.rb

Overview

A CloudFormation template section

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, limit = nil) ⇒ Section

  • name: The section’s name (Resources, Outputs, etc.)

  • type: The section’s type (Hash or String)

  • limit: The AWS limit for this section, if any



11
12
13
14
15
16
# File 'lib/mkstack/section.rb', line 11

def initialize(name, type, limit = nil)
  @name = name
  @limit = limit

  @contents = type.new
end

Instance Attribute Details

#contentsObject

Returns the value of attribute contents.



6
7
8
# File 'lib/mkstack/section.rb', line 6

def contents
  @contents
end

#limitObject (readonly)

Returns the value of attribute limit.



5
6
7
# File 'lib/mkstack/section.rb', line 5

def limit
  @limit
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/mkstack/section.rb', line 5

def name
  @name
end

Instance Method Details

#exceeds_limit?Boolean

Check if the section exceeds the AWS limit

Returns:

  • (Boolean)


37
# File 'lib/mkstack/section.rb', line 37

def exceeds_limit?; @limit && length > @limit; end

#lengthObject

Return the length of the section’s contents



34
# File 'lib/mkstack/section.rb', line 34

def length; @contents.length; end

#merge(contents) ⇒ Object

Merge or override a section snippet



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mkstack/section.rb', line 19

def merge(contents)
  # Hashes get merged
  return @contents.merge!(contents) if @contents.respond_to?(:merge!)

  # Arrays get concatenated or pushed
  if @contents.respond_to?(:push)
    return @contents.concat(contents) if contents.respond_to?(:push)
    return @contents.push(contents)
  end

  # Strings get copied
  @contents = contents
end