Class: Terracop::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/terracop/runner.rb

Overview

Executes Terracop on a given state file.

Instance Method Summary collapse

Constructor Details

#initialize(type, file, formatter) ⇒ Runner

Returns a new instance of Runner.



6
7
8
9
10
11
# File 'lib/terracop/runner.rb', line 6

def initialize(type, file, formatter)
  @formatter = Formatters.const_get(formatter.to_s.capitalize).new

  @type = type
  @file = file
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/terracop/runner.rb', line 13

def run
  offenses = state.map do |instance|
    Terracop::Cop.run_for(
      instance[:type], instance[:name],
      instance[:index], instance[:attributes]
    )
  end

  print formatted(offenses)

  offenses.flatten.count
end

#stateObject



26
27
28
29
30
31
32
33
34
# File 'lib/terracop/runner.rb', line 26

def state
  @state ||= begin
    if @file
      load_state_from_file(@type, @file)
    else
      load_state_from_terraform
    end
  end
end