Class: Goodcheck::Unarchiver
- Inherits:
-
Object
- Object
- Goodcheck::Unarchiver
- Defined in:
- lib/goodcheck/unarchiver.rb
Instance Attribute Summary collapse
-
#file_filter ⇒ Object
readonly
Returns the value of attribute file_filter.
Instance Method Summary collapse
-
#initialize(file_filter: ->(_filename) { true }) ⇒ Unarchiver
constructor
A new instance of Unarchiver.
- #tar_gz(content) ⇒ Object
- #tar_gz?(filename) ⇒ Boolean
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_filter ⇒ Object (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
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 |