Class: Rezip::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/rezip/cli.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

A hack to get ‘default_task` to work with an argument



33
34
35
# File 'lib/rezip/cli.rb', line 33

def method_missing(method, *args, &block)
  rezip method.to_s
end

Instance Method Details

#rezip(file) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rezip/cli.rb', line 10

def rezip(file)
  unless File.exists? file
    puts "rezip: #{file}: no such file"
    exit
  end

  Zip::File.open file do |archive|
    # Delete files
    archive.each do |entry|
      FileUtils.rm entry.name
    end

    # Delete directories
    directories = archive.select { |e| e.name.include? '/' }.map { |e| e.name.split('/').first }.uniq
    directories.each do |entry|
      FileUtils.rm_rf entry
    end
  end
rescue Zip::Error
  puts "rezip: #{file}: invalid zip archive"
end