Class: Unzip

Inherits:
Object
  • Object
show all
Includes:
Albacore::Task
Defined in:
lib/albacore/unzip.rb

Instance Attribute Summary collapse

Attributes included from Logging

#current_log_device, #logger

Instance Method Summary collapse

Methods included from Albacore::Task

clean_dirname, create_rake_task, include_config, included

Methods included from UpdateAttributes

#<<, #update_attributes

Methods included from YAMLConfig

#configure, #load_config_by_task_name

Methods included from Logging

#create_logger, #log_device=, #log_level, #log_level=

Methods included from Failure

#fail_with_message

Constructor Details

#initializeUnzip

Returns a new instance of Unzip.



11
12
13
14
# File 'lib/albacore/unzip.rb', line 11

def initialize
  super()
  update_attributes Albacore.configuration.unzip.to_hash
end

Instance Attribute Details

#destinationObject

Returns the value of attribute destination.



9
10
11
# File 'lib/albacore/unzip.rb', line 9

def destination
  @destination
end

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/albacore/unzip.rb', line 9

def file
  @file
end

Instance Method Details

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/albacore/unzip.rb', line 16

def execute()
  fail_with_message 'Zip File cannot be empty' if @file.nil?
  return if @file.nil?

  Zip::ZipFile.open(@file) do |zip_f|
      zip_f.each do |f|
         out_path = File.join(@destination, f.name)
         FileUtils.mkdir_p(File.dirname(out_path))
         zip_f.extract(f, out_path) unless File.exist?(out_path)
      end
    end
end