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.
53 54 55 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 53 def initialize(template) @template = template end |
Class Method Details
.format(template) ⇒ Object
49 50 51 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 49 def self.format(template) new(template).format end |
Instance Method Details
#format ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/stack_master/sparkle_formation/template_file.rb', line 57 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 |