Class: MkStack::Section
- Inherits:
-
Object
- Object
- MkStack::Section
- Defined in:
- lib/mkstack/section.rb
Overview
A CloudFormation template section
Instance Attribute Summary collapse
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#exceeds_limit? ⇒ Boolean
Check if the section exceeds the AWS limit.
-
#initialize(name, type, limit = nil) ⇒ Section
constructor
-
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.
-
-
#length ⇒ Object
Return the length of the section’s contents.
-
#merge(contents) ⇒ Object
Merge or override a section snippet.
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
#contents ⇒ Object
Returns the value of attribute contents.
6 7 8 |
# File 'lib/mkstack/section.rb', line 6 def contents @contents end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
5 6 7 |
# File 'lib/mkstack/section.rb', line 5 def limit @limit end |
#name ⇒ Object (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
37 |
# File 'lib/mkstack/section.rb', line 37 def exceeds_limit?; @limit && length > @limit; end |
#length ⇒ Object
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 |