class RakeDependencies::Extractors::ZipExtractor
Public Class Methods
new(file_path, extract_path, options = {})
click to toggle source
# File lib/rake_dependencies/extractors.rb, line 9 def initialize(file_path, extract_path, options = {}) @file_path = file_path @extract_path = extract_path @options = options end
Public Instance Methods
extract()
click to toggle source
# File lib/rake_dependencies/extractors.rb, line 15 def extract FileUtils.mkdir_p(@extract_path) Zip::File.open(@file_path) do |zip_file_entries| zip_file_entries.restore_permissions = true zip_file_entries.each do |entry| entry_pathname = Pathname.new(entry.name) strip_pathname = Pathname.new(@options[:strip_path] || '') target_pathname = entry_pathname.relative_path_from(strip_pathname) file_path = File.join(@extract_path, target_pathname) FileUtils.mkdir_p(File.dirname(file_path)) zip_file_entries.extract(entry, file_path) unless File.exist?(file_path) end end if @options[:rename_from] && @options[:rename_to] FileUtils.mkdir_p( File.dirname(File.join(@extract_path, @options[:rename_to]))) FileUtils.mv( File.join(@extract_path, @options[:rename_from]), File.join(@extract_path, @options[:rename_to])) end end