Class: TerraformLandscape::TerraformPlan
- Inherits:
-
Object
- Object
- TerraformLandscape::TerraformPlan
- Defined in:
- lib/terraform_landscape/terraform_plan.rb
Overview
Represents the parsed output of ‘terraform plan`.
This allows us to easily inspect the plan and present a more readable explanation of the plan to the user.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- GRAMMAR_FILE =
rubocop:disable Metrics/ClassLength
File.(File.join(File.dirname(__FILE__), '..', '..', 'grammar', 'terraform_plan.treetop'))
- CHANGE_SYMBOL_TO_COLOR =
{ :~ => :yellow, :- => :red, :+ => :green, :'-/+' => :yellow, :'<=' => :cyan }.freeze
- DEFAULT_DIFF_CONTEXT_LINES =
5
Class Method Summary collapse
Instance Method Summary collapse
- #display(output) ⇒ Object
-
#initialize(plan_ast, options = {}) ⇒ TerraformPlan
constructor
Create a plan from an abstract syntax tree (AST).
Constructor Details
#initialize(plan_ast, options = {}) ⇒ TerraformPlan
Create a plan from an abstract syntax tree (AST).
52 53 54 55 |
# File 'lib/terraform_landscape/terraform_plan.rb', line 52 def initialize(plan_ast, = {}) @ast = plan_ast @diff_context_lines = .fetch(:diff_context_lines, DEFAULT_DIFF_CONTEXT_LINES) end |
Class Method Details
.from_output(string) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/terraform_landscape/terraform_plan.rb', line 30 def from_output(string) # Our grammar assumes output with Unix line endings string = string.gsub("\r\n", "\n") return new([]) if string.strip.empty? tree = parser.parse(string) raise ParseError, parser.failure_reason unless tree new(tree.to_ast) end |
Instance Method Details
#display(output) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/terraform_landscape/terraform_plan.rb', line 57 def display(output) @out = output @ast.each do |resource| display_resource(resource) @out.newline end end |