Module: Packer::Binary

Defined in:
lib/packer/binary.rb,
lib/packer/binary/command.rb,
lib/packer/binary/helpers.rb,
lib/packer/binary/version.rb,
lib/packer/binary/compressor.rb,
lib/packer/binary/executable.rb

Overview

The Binary namespace handles sub-commands using #method_missing metaprogramming as well as the global configuration object

Defined Under Namespace

Modules: Command, Helpers Classes: Compressor, Configuration, Executable

Constant Summary collapse

VERSION =

Gem Version

'0.2.3'.freeze
PACKER_VERSION =

The version number of the Packer binary to download and use

'1.0.4'.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)

Note:

if the method is an invalid sub-command or if the command fails you will get a Packer::Binary::Command::CommandFailure exception

This method maps Packer::Binary method calls to Packer sub-commands Ex. to run packer build test.json -machine-readable:

Packer::Binary.build('test.json -machine-readable')

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
# File 'lib/packer/binary.rb', line 42

def method_missing(method, *args, &block)
  if method.to_s =~ /(\w+)/
    Packer::Binary::Helpers.debug("#{method.to_s.downcase} #{args.join(' ')}")
    Command.run("#{method.to_s.downcase} #{args.join(' ')}")
  else
    super
  end
end

Instance Attribute Details

#config=(value) ⇒ Object

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



18
# File 'lib/packer/binary.rb', line 18

attr_writer :config

Class Method Details

.configObject

defines the @config class variable



23
24
25
# File 'lib/packer/binary.rb', line 23

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Set the global settings. See the README for more information

Yields:



28
29
30
# File 'lib/packer/binary.rb', line 28

def configure
  yield(config)
end

.method_missing(method, *args, &block) ⇒ Object

Note:

if the method is an invalid sub-command or if the command fails you will get a Packer::Binary::Command::CommandFailure exception

This method maps Packer::Binary method calls to Packer sub-commands Ex. to run packer build test.json -machine-readable:

Packer::Binary.build('test.json -machine-readable')

Since:

  • 0.2.0



42
43
44
45
46
47
48
49
# File 'lib/packer/binary.rb', line 42

def method_missing(method, *args, &block)
  if method.to_s =~ /(\w+)/
    Packer::Binary::Helpers.debug("#{method.to_s.downcase} #{args.join(' ')}")
    Command.run("#{method.to_s.downcase} #{args.join(' ')}")
  else
    super
  end
end

.respond_to_missing?(method) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/packer/binary.rb', line 51

def respond_to_missing?(method, *)
  method =~ /(\w+)/ || super
end

.VersionObject

Deprecated.

Use #method_missing dynamic method handling for binary sub-commands

The Convenience methods have been deprecated in favor of dynamic method handling.



59
60
61
# File 'lib/packer/binary.rb', line 59

def Version
  Command.run('version')
end