lib/app_info/ipa.rb in app-info-2.8.5 vs lib/app_info/ipa.rb in app-info-3.0.0.beta1

- old
+ new

@@ -5,11 +5,11 @@ require 'forwardable' require 'cfpropertylist' module AppInfo # IPA parser - class IPA + class IPA < File include Helper::HumanFileSize include Helper::Archive extend Forwardable attr_reader :file @@ -23,22 +23,30 @@ UNKOWN = nil INHOUSE = 'Enterprise' # Rename and Alias to enterprise end - def initialize(file) - @file = file - end - + # return file size + # @example Read file size in integer + # aab.size # => 3618865 + # + # @example Read file size in human readabale + # aab.size(human_size: true) # => '3.45 MB' + # + # @param [Boolean] human_size Convert integer value to human readable. + # @return [Integer, String] def size(human_size: false) file_to_human_size(@file, human_size: human_size) end - def os + def file_type + Format::IPA + end + + def platform Platform::IOS end - alias file_type os def_delegators :info, :iphone?, :ipad?, :universal?, :build_version, :name, :release_version, :identifier, :bundle_id, :display_name, :bundle_name, :min_sdk_version, :min_os_version, :device_type @@ -68,11 +76,11 @@ ExportType::DEBUG end end def archs - return unless File.exist?(bundle_path) + return unless ::File.exist?(bundle_path) file = MachO.open(bundle_path) case file when MachO::MachOFile [file.cpusubtype] @@ -112,18 +120,18 @@ @mobileprovision = MobileProvision.new(mobileprovision_path) end def mobileprovision? - File.exist?(mobileprovision_path) + ::File.exist?(mobileprovision_path) end def mobileprovision_path filename = 'embedded.mobileprovision' - @mobileprovision_path ||= File.join(@file, filename) - unless File.exist?(@mobileprovision_path) - @mobileprovision_path = File.join(app_path, filename) + @mobileprovision_path ||= ::File.join(@file, filename) + unless ::File.exist?(@mobileprovision_path) + @mobileprovision_path = ::File.join(app_path, filename) end @mobileprovision_path end @@ -132,55 +140,52 @@ @metadata ||= CFPropertyList.native_types(CFPropertyList::List.new(file: metadata_path).value) end def metadata? - File.exist?(metadata_path) + ::File.exist?(metadata_path) end def metadata_path - @metadata_path ||= File.join(contents, 'iTunesMetadata.plist') + @metadata_path ||= ::File.join(contents, 'iTunesMetadata.plist') end def bundle_path - @bundle_path ||= File.join(app_path, info.bundle_name) + @bundle_path ||= ::File.join(app_path, info.bundle_name) end def info @info ||= InfoPlist.new(info_path) end def info_path - @info_path ||= File.join(app_path, 'Info.plist') + @info_path ||= ::File.join(app_path, 'Info.plist') end def app_path - @app_path ||= Dir.glob(File.join(contents, 'Payload', '*.app')).first + @app_path ||= Dir.glob(::File.join(contents, 'Payload', '*.app')).first end IPHONE_KEY = 'CFBundleIcons' IPAD_KEY = 'CFBundleIcons~ipad' def icons_path - return @icons_path if @icons_path + @icons_path ||= lambda { + icon_keys.each_with_object([]) do |name, icons| + filenames = info.try(:[], name) + .try(:[], 'CFBundlePrimaryIcon') + .try(:[], 'CFBundleIconFiles') - @icons_path = [] - icon_keys.each do |name| - filenames = info.try(:[], name) - .try(:[], 'CFBundlePrimaryIcon') - .try(:[], 'CFBundleIconFiles') + next if filenames.nil? || filenames.empty? - next if filenames.nil? || filenames.empty? - - filenames.each do |filename| - Dir.glob(File.join(app_path, "#{filename}*")).find_all.each do |file| - @icons_path << file + filenames.each do |filename| + Dir.glob(::File.join(app_path, "#{filename}*")).find_all.each do |file| + icons << file + end end end - end - - @icons_path + }.call end def clear! return unless @contents @@ -195,30 +200,30 @@ @icons_path = nil @icons = nil end def contents - @contents ||= unarchive(@file, path: 'ios') + @contents ||= unarchive(@file, prefix: 'ios') end private def build_icon_metadata(file, uncrush: true) uncrushed_file = uncrush ? uncrush_png(file) : nil { - name: File.basename(file), + name: ::File.basename(file), file: file, uncrushed_file: uncrushed_file, dimensions: PngUncrush.dimensions(file) } end # Uncrush png to normal png file (iOS) def uncrush_png(src_file) dest_file = tempdir(src_file, prefix: 'uncrushed') PngUncrush.decompress(src_file, dest_file) - File.exist?(dest_file) ? dest_file : nil + ::File.exist?(dest_file) ? dest_file : nil end def icon_keys @icon_keys ||= case device_type when 'iPhone'