Class: TerraformWrapper::Shared::Binary

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/terraform-wrapper/shared/binary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

configure_logger_for, logger_for

Constructor Details

#initialize(options:, provider:) ⇒ Binary

Returns a new instance of Binary.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/terraform-wrapper/shared/binary.rb', line 31

def initialize(options:, provider:)
  logger.fatal("Binary base path must be a string!") unless options["base"].kind_of?(String)
  logger.fatal("Binary base path must not be blank!") if options["base"].strip.empty?

  @base = options["base"]

  logger.fatal("Binary version must be a string!") unless options["version"].kind_of?(String)
  logger.fatal("Binary version must not be blank!") if options["version"].strip.empty?

  @version = options["version"]

  @platform = platform_detect
  @directory = File.join(@base, @version, @platform)
  @provider = provider
  @name = "terraform"
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



23
24
25
# File 'lib/terraform-wrapper/shared/binary.rb', line 23

def base
  @base
end

#directoryObject (readonly)

Returns the value of attribute directory.



24
25
26
# File 'lib/terraform-wrapper/shared/binary.rb', line 24

def directory
  @directory
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/terraform-wrapper/shared/binary.rb', line 19

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform.



26
27
28
# File 'lib/terraform-wrapper/shared/binary.rb', line 26

def platform
  @platform
end

#providerObject (readonly)

Returns the value of attribute provider.



25
26
27
# File 'lib/terraform-wrapper/shared/binary.rb', line 25

def provider
  @provider
end

#versionObject (readonly)

Returns the value of attribute version.



27
28
29
# File 'lib/terraform-wrapper/shared/binary.rb', line 27

def version
  @version
end

Instance Method Details

#checkObject



50
51
52
53
54
55
56
57
58
# File 'lib/terraform-wrapper/shared/binary.rb', line 50

def check()
  result = false

  if exists and executable then
    result = system("\"#{path}\" version") || false
  end

  return result
end

#executableObject



68
69
70
# File 'lib/terraform-wrapper/shared/binary.rb', line 68

def executable()
  return File.executable?(path)
end

#existsObject



62
63
64
# File 'lib/terraform-wrapper/shared/binary.rb', line 62

def exists()
  return File.exist?(path)
end

#pathObject



74
75
76
# File 'lib/terraform-wrapper/shared/binary.rb', line 74

def path()
  return File.join(@directory, @name)
end