Class: Packer::Binary::Executable
- Inherits:
-
Object
- Object
- Packer::Binary::Executable
- Includes:
- Helpers
- Defined in:
- lib/packer/binary/executable.rb
Overview
This class handles downloading, extracting, and saving the associated binary file
Defined Under Namespace
Classes: PlatformUnsupported
Constant Summary collapse
- PACKER_DOWNLOAD_URI =
The download URI for the binary package
'releases.hashicorp.com'.freeze
Instance Method Summary collapse
-
#binary ⇒ String
Returns the path to the binary if it exists.
-
#download ⇒ Object
Downloads the zipfile from the origin.
-
#extract ⇒ Object
Extracts the binary from the zipfile and makes it executable.
-
#initialize ⇒ Executable
constructor
Loads global config values and creates the download directory if the current platform is supported.
Methods included from Helpers
debug, err, msg, system_command
Constructor Details
#initialize ⇒ Executable
Loads global config values and creates the download directory if the current platform is supported
16 17 18 19 20 21 22 23 24 |
# File 'lib/packer/binary/executable.rb', line 16 def initialize @packer_version = Packer::Binary.config.version @download_path = "#{Packer::Binary.config.download_path.chomp('/')}/packer-binary/#{@packer_version}/bin" @download_filename = "#{@packer_version}-packer.zip" FileUtils.mkdir_p @download_path raise PlatformUnsupported unless supported? end |
Instance Method Details
#binary ⇒ String
Returns the path to the binary if it exists
28 29 30 |
# File 'lib/packer/binary/executable.rb', line 28 def binary Dir["#{@download_path}/packer*"][0] end |
#download ⇒ Object
Downloads the zipfile from the origin
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/packer/binary/executable.rb', line 33 def download return if binary_exist? msg("Downloading https://#{download_domain}/#{download_uri}") require 'open-uri' File.open("#{@download_path}/#{@download_filename}", 'wb') do |saved_file| # the following "open" is provided by open-uri open("https://#{download_domain}/#{download_uri}", 'rb') do |read_file| saved_file.write(read_file.read) end end end |
#extract ⇒ Object
Extracts the binary from the zipfile and makes it executable
49 50 51 52 53 54 |
# File 'lib/packer/binary/executable.rb', line 49 def extract return if binary_exist? Compressor.extract("#{@download_path}/#{@download_filename}", @download_path) make_exe end |