Class: RubyTerraform::Commands::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_terraform/commands/base.rb

Direct Known Subclasses

Apply, Destroy, Get, Init, Output, Plan, Refresh, RemoteConfig, Show, Validate, Workspace

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'lib/ruby_terraform/commands/base.rb', line 8

def initialize(binary: nil, logger: nil, stdin: nil, stdout: nil, stderr: nil)
  @binary = binary || RubyTerraform.configuration.binary
  @logger = logger || RubyTerraform.configuration.logger
  @stdin = stdin || RubyTerraform.configuration.stdin
  @stdout = stdout || RubyTerraform.configuration.stdout
  @stderr = stderr || RubyTerraform.configuration.stderr
end

Instance Attribute Details

#binaryObject (readonly)

Returns the value of attribute binary.



6
7
8
# File 'lib/ruby_terraform/commands/base.rb', line 6

def binary
  @binary
end

Instance Method Details

#configure_command(builder, opts) ⇒ Object



53
54
# File 'lib/ruby_terraform/commands/base.rb', line 53

def configure_command(builder, opts)
end

#do_after(opts) ⇒ Object



56
57
# File 'lib/ruby_terraform/commands/base.rb', line 56

def do_after(opts)
end

#do_before(opts) ⇒ Object



50
51
# File 'lib/ruby_terraform/commands/base.rb', line 50

def do_before(opts)
end

#execute(opts = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ruby_terraform/commands/base.rb', line 28

def execute(opts = {})
  builder = instantiate_builder

  do_before(opts)
  command = configure_command(builder, opts)
              .build
  @logger.debug "Running #{command.to_s}"

  command.execute(
    stdin: stdin,
    stdout: stdout,
    stderr: stderr
  )
  do_after(opts)
end

#instantiate_builderObject



44
45
46
47
48
# File 'lib/ruby_terraform/commands/base.rb', line 44

def instantiate_builder
  Lino::CommandLineBuilder
      .for_command(binary)
      .with_option_separator('=')
end

#stderrObject



24
25
26
# File 'lib/ruby_terraform/commands/base.rb', line 24

def stderr
  @stderr
end

#stdinObject



16
17
18
# File 'lib/ruby_terraform/commands/base.rb', line 16

def stdin
  @stdin
end

#stdoutObject



20
21
22
# File 'lib/ruby_terraform/commands/base.rb', line 20

def stdout
  @stdout
end