Class: Puppet::Module::Tool::Applications::Unpacker

Inherits:
Application
  • Object
show all
Defined in:
lib/puppet/module/tool/applications/unpacker.rb

Instance Attribute Summary

Attributes inherited from Application

#options

Instance Method Summary collapse

Methods inherited from Application

#discuss, #load_modulefile!, #metadata, #parse_filename!, #repository, run

Methods included from Utils::Interrogation

#confirms?, #header, #prompt, #say, #subheader

Constructor Details

#initialize(filename, environment_path, options = {}) ⇒ Unpacker

Returns a new instance of Unpacker.



10
11
12
13
14
15
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 10

def initialize(filename, environment_path, options = {})
  @filename = Pathname.new(filename)
  @environment_path = Pathname.new(environment_path)
  parse_filename!
  super(options)
end

Instance Method Details

#force?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 17

def force?
  options[:force]
end

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/puppet/module/tool/applications/unpacker.rb', line 21

def run
  check_clobber!
  build_dir = Puppet::Module::Tool::Cache.base_path + "tmp-unpacker-#{Digest::SHA1.hexdigest(@filename.basename)}"
  build_dir.mkpath
  begin
    FileUtils.cp @filename, build_dir
    Dir.chdir(build_dir) do
      unless system "tar xzf #{@filename.basename}"
        abort "Could not extract contents of module archive."
      end
    end
    # grab the first directory
    extracted = build_dir.children.detect { |c| c.directory? }
    if force?
      FileUtils.rm_rf @full_name rescue nil
    end
    FileUtils.cp_r extracted, @full_name
    tag_revision
  ensure
    build_dir.rmtree
  end
  say "Installed #{@release_name.inspect} into directory: #{@full_name}"
end