class PackRb::Packer
Public Class Methods
new(opts = {})
click to toggle source
# File lib/pack_rb/packer.rb, line 25 def initialize(opts = {}) @machine_readable = opts[:machine_readable] @bin_path = opts[:bin_path] @tpl = opts[:tpl] @stream_output = opts.fetch(:stream_output, false) end
Public Instance Methods
bin()
click to toggle source
# File lib/pack_rb/packer.rb, line 40 def bin return bin_path if bin_path # some distros, such as Arch Linux, package the Packer # binary as ``packer-io`` ['packer', 'packer-io'].each do |bin_name| p = find_executable(bin_name) return p if p end raise RuntimeError, "Could not find packer or packer-io binary on path." \ " Please specify the full binary path with the " \ "'bin_path' option." end
command()
click to toggle source
# File lib/pack_rb/packer.rb, line 32 def command if machine_readable "#{bin} -machine-readable" else bin end end
commander()
click to toggle source
# File lib/pack_rb/packer.rb, line 58 def commander @commander ||= PackRb::SubCommands.new(stream_output: @stream_output) end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/pack_rb/packer.rb, line 62 def method_missing(name, *args, &block) return super unless commander.respond_to?(name) opts = { base_cmd: command, tpl: template, args: args.first } commander.send(name, opts) end
template()
click to toggle source
# File lib/pack_rb/packer.rb, line 53 def template obj = @tpl json?(obj) || path?(obj) || hash?(obj) end
Private Instance Methods
bin_path()
click to toggle source
# File lib/pack_rb/packer.rb, line 96 def bin_path @bin_path end
can_match?(obj)
click to toggle source
# File lib/pack_rb/packer.rb, line 76 def can_match?(obj) obj.respond_to?(:match) end
hash?(obj)
click to toggle source
# File lib/pack_rb/packer.rb, line 92 def hash?(obj) obj.to_json end
json?(obj)
click to toggle source
# File lib/pack_rb/packer.rb, line 84 def json?(obj) can_match?(obj) && like_json?(obj) && obj end
like_json?(obj)
click to toggle source
# File lib/pack_rb/packer.rb, line 80 def like_json?(obj) obj.match(/{.*}/) end
machine_readable()
click to toggle source
# File lib/pack_rb/packer.rb, line 100 def machine_readable @machine_readable end
path?(obj)
click to toggle source
# File lib/pack_rb/packer.rb, line 88 def path?(obj) can_match?(obj) && File.read(obj) end