Class: StackMaster::SparkleFormation::CloudFormationLineFormatter
- Inherits:
-
Object
- Object
- StackMaster::SparkleFormation::CloudFormationLineFormatter
- Defined in:
- lib/stack_master/sparkle_formation/template_file.rb
Overview
Splits up long strings with multiple lines in them to multiple strings in the CF array. Makes the compiled template and diffs more readable.
Class Method Summary collapse
Instance Method Summary collapse
- #format ⇒ Object
-
#initialize(template) ⇒ CloudFormationLineFormatter
constructor
A new instance of CloudFormationLineFormatter.
Constructor Details
#initialize(template) ⇒ CloudFormationLineFormatter
Returns a new instance of CloudFormationLineFormatter.
59 60 61 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 59 def initialize(template) @template = template end |
Class Method Details
.format(template) ⇒ Object
55 56 57 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 55 def self.format(template) new(template).format end |
Instance Method Details
#format ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 63 def format @template.flat_map do |lines| lines = lines.to_s if Symbol === lines if String === lines newlines = [] lines.count("\n").times do newlines << "\n" end newlines = lines.split("\n").map do |line| "#{line}#{newlines.pop}" end if lines.starts_with?("\n") newlines.insert(0, "\n") end newlines else lines end end end |