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)


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

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

#lengthObject

Return the length of the section’s contents



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

def length; @contents.length; end

#merge(contents) ⇒ Object

Merge or override a section snippet

Raises:

  • (TypeError)


19
20
21
22
23
24
# File 'lib/mkstack/section.rb', line 19

def merge(contents)
  raise TypeError.new("#{contents.class} != #{@contents.class}") if contents.class != @contents.class

  return @contents.merge!(contents) if @contents.respond_to?(:merge!)
  @contents = contents
end