module CFBundle::StorageDetection
@private
Utility methods required to detect and instantiate a bundle's storage.
Public Class Methods
open(file)
click to toggle source
Opens a file and returns a bundle storage. @param file The file to open. @return [Storage]
# File lib/cfbundle/storage_detection.rb, line 14 def open(file) storage = open_as_storage(file) || open_as_io(file) || open_as_path(file) raise "#{file.inspect} is not a bundle" unless storage storage end
Private Class Methods
matching_zip_entry(zip)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 67 def matching_zip_entry(zip) entries = zip.entries.select { |entry| zip_entry_match?(entry) } case entries.count when 1 entries.first when 0 raise "no bundle found in ZIP archive \"#{zip}\"" else raise "several bundles found in ZIP archive \"#{zip}\"" end end
open_as_io(file)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 46 def open_as_io(file) open_zip_io(file.to_io) if file.respond_to?(:to_io) end
open_as_path(file)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 36 def open_as_path(file) path = path_for(file) || return ext = File.extname(path) if File.directory?(path) && ext != '' Storage::FileSystem.new(path) elsif ['.ipa', '.zip'].include? ext open_zip_path(path) end end
open_as_storage(file)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 32 def open_as_storage(file) file if file.is_a?(Storage::Base) end
open_zip_file(file, skip_close: false) { |File, file| ... }
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 58 def open_zip_file(file, skip_close: false) unless defined?(Zip) raise "cannot open ZIP archive #{file.inspect} without Rubyzip" end zip = yield(Zip::File, file) entry = matching_zip_entry(zip) Storage::Zip.new(zip, entry.name, skip_close: skip_close) end
open_zip_io(io)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 54 def open_zip_io(io) open_zip_file(io, &:open_buffer) end
open_zip_path(path)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 50 def open_zip_path(path) open_zip_file(path, &:open) end
path_for(file)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 24 def path_for(file) if file.is_a? String file elsif file.respond_to? :to_path file.to_path end end
zip_entry_match?(entry)
click to toggle source
# File lib/cfbundle/storage_detection.rb, line 79 def zip_entry_match?(entry) entry.directory? && [nil, 'Payload/'].include?(entry.parent_as_string) && File.extname(entry.name) != '' end