Class: Goodcheck::Unarchiver

Inherits:
Object
  • Object
show all
Defined in:
lib/goodcheck/unarchiver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_filter: ->(_filename) { true }) ⇒ Unarchiver

Returns a new instance of Unarchiver.



5
6
7
# File 'lib/goodcheck/unarchiver.rb', line 5

def initialize(file_filter: ->(_filename) { true })
  @file_filter = file_filter
end

Instance Attribute Details

#file_filterObject (readonly)

Returns the value of attribute file_filter.



3
4
5
# File 'lib/goodcheck/unarchiver.rb', line 3

def file_filter
  @file_filter
end

Instance Method Details

#tar_gz(content) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/goodcheck/unarchiver.rb', line 15

def tar_gz(content)
  require "rubygems/package"

  Gem::Package::TarReader.new(StringIO.new(gz(content))) do |tar_reader|
    tar_reader.each do |file|
      if file.file? && file_filter.call(file.full_name)
        yield file.read, file.full_name
      end
    end
  end
end

#tar_gz?(filename) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/goodcheck/unarchiver.rb', line 9

def tar_gz?(filename)
  name = filename.to_s.downcase
  ext = ".tar.gz"
  name.end_with?(ext) && name != ext
end