Module: AppleEpf::Main::BaseActions

Defined in:
lib/apple_epf/main.rb

Instance Method Summary collapse

Instance Method Details

#download(filename) ⇒ Object



79
80
81
82
83
84
# File 'lib/apple_epf/main.rb', line 79

def download(filename)
  downloader = AppleEpf::Downloader.new(type, filename.to_s, @filedate)
  downloader.dirpath = @store_dir if @store_dir
  downloader.download
  downloader
end

#download_all_files(&block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/apple_epf/main.rb', line 37

def download_all_files(&block)
  downloaded_files = []

  @files_matrix.each_pair do |filename, extractables|
    begin
      downloaded = self.download(filename)
      downloaded_files << downloaded
      block.call(downloaded) if block_given?
    rescue AppleEpf::DownloaderError
      AppleEpf::Logging.logger.fatal "Failed to download file #{filename}"
      AppleEpf::Logging.logger.fatal $!
      next
    end
  end

  downloaded_files
end

#download_and_extract(filename, extractables) ⇒ Object

will return array of filepath of extracted files



73
74
75
76
77
# File 'lib/apple_epf/main.rb', line 73

def download_and_extract(filename, extractables)
  downloader = self.download(filename.to_s)
  downloaded_file = downloader.download_to
  self.extract(downloaded_file, extractables)
end

#download_and_extract_all_files(&block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/apple_epf/main.rb', line 55

def download_and_extract_all_files(&block)
  extracted_files = []

  @files_matrix.each_pair do |filename, extractables|
    begin
      extracted_file = download_and_extract(filename.to_s, extractables)
      extracted_files << extracted_file
      block.call(extracted_file) if block_given?
    rescue
      AppleEpf::Logging.logger.fatal "Failed to download and parse file #{filename}"
      next
    end
  end

  extracted_files
end

#extract(downloaded_file, extractables) ⇒ Object



86
87
88
89
90
91
# File 'lib/apple_epf/main.rb', line 86

def extract(downloaded_file, extractables)
  extractor = AppleEpf::Extractor.new(downloaded_file, extractables)
  extractor.keep_tbz_after_extract = @keep_tbz_after_extract if @keep_tbz_after_extract
  extractor.perform
  extractor.file_entry
end