Class: Pione::Package::PackageExpander

Inherits:
Object
  • Object
show all
Defined in:
lib/pione/package/package-expander.rb

Overview

PackageExpander expands package files from ZIP archive.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ PackageExpander

Create a instance with the target location.

Parameters:

  • location (BasicLoaction)

    package location



11
12
13
# File 'lib/pione/package/package-expander.rb', line 11

def initialize(location)
  @location = location
end

Instance Attribute Details

#locationObject (readonly)

Returns the value of attribute location.



5
6
7
# File 'lib/pione/package/package-expander.rb', line 5

def location
  @location
end

Instance Method Details

#expand(output) ⇒ Object

Expand package files into the output location.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pione/package/package-expander.rb', line 16

def expand(output)
  # make local cache of target location
  location = @location.local

  # expand zip archive
  Zip::File.open(location.path.to_s) do |zip|
    zip.each do |entry|
      unless entry.ftype == :directory
        tmp = Temppath.create
        entry.extract(tmp.to_s)
        Location[tmp].move(output + entry.name)
      end
    end
  end
end