Class: Terraspace::All::Preview

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Compiler::DirsConcern, Util::Logging
Defined in:
lib/terraspace/all/preview.rb

Instance Method Summary collapse

Methods included from Compiler::DirsConcern

#cache_dirs, #dirs, #extract_stack_name, #local_paths, #mod_names, #select_stack?, #stack_names, #with_each_mod

Methods included from Util::Logging

#logger

Constructor Details

#initialize(command, batches, options = {}) ⇒ Preview

Returns a new instance of Preview.



7
8
9
# File 'lib/terraspace/all/preview.rb', line 7

def initialize(command, batches, options={})
  @command, @batches, @options = command, batches, options
end

Instance Method Details

#headerObject



16
17
18
# File 'lib/terraspace/all/preview.rb', line 16

def header
  %w[up down].include?(@command) && !@options[:yes] ? "Will run:" : "Running:"
end

#max_name_sizeObject



33
34
35
36
37
38
39
40
# File 'lib/terraspace/all/preview.rb', line 33

def max_name_size
  @batches.inject(0) do |max,batch|
    batch.each do |node|
      max = node.name.size if node.name.size > max
    end
    max
  end
end

#previewObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/terraspace/all/preview.rb', line 20

def preview
  i = 0
  @batches.map do |batch|
    i += 1
    batch.map do |stack|
      command = "    terraspace #{@command}"
      ljust = command.size + max_name_size + 1
      command = "#{command} #{stack.name}"
      command.ljust(ljust, ' ') + " # batch #{i}"
    end
  end.join("\n")
end

#showObject



11
12
13
14
# File 'lib/terraspace/all/preview.rb', line 11

def show
  logger.info header
  logger.info preview
end