Class: ExtractionCache
- Inherits:
-
Object
- Object
- ExtractionCache
- Defined in:
- lib/wonko_the_sane/util/extraction_cache.rb
Class Method Summary collapse
Instance Method Summary collapse
- #get(archive, type, file) ⇒ Object
-
#initialize(basedir) ⇒ ExtractionCache
constructor
A new instance of ExtractionCache.
Constructor Details
#initialize(basedir) ⇒ ExtractionCache
Returns a new instance of ExtractionCache.
2 3 4 5 |
# File 'lib/wonko_the_sane/util/extraction_cache.rb', line 2 def initialize(basedir) @basedir = basedir FileUtils.mkdir_p @basedir unless Dir.exist? @basedir end |
Class Method Details
.get(archive, type, file) ⇒ Object
21 22 23 24 |
# File 'lib/wonko_the_sane/util/extraction_cache.rb', line 21 def self.get(archive, type, file) @cache ||= ExtractionCache.new 'cache/extraction' @cache.get archive, type, file end |
Instance Method Details
#get(archive, type, file) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wonko_the_sane/util/extraction_cache.rb', line 7 def get(archive, type, file) out = path(archive, type, file) FileUtils.mkdir_p File.dirname(out) unless Dir.exist? File.dirname(out) unless File.exist? out if type == :zip Zip::File.open archive do |arch| File.write out, arch.glob(file).first.get_input_stream.read end end end File.read out end |