Class: AppInfo::Macos

Inherits:
Object show all
Extended by:
Forwardable
Includes:
Helper::Archive, Helper::HumanFileSize
Defined in:
lib/app_info/macos.rb

Overview

MacOS App parser

Defined Under Namespace

Modules: ExportType

Constant Summary

Constants included from Helper::HumanFileSize

Helper::HumanFileSize::FILE_SIZE_UNITS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper::Archive

#tempdir, #unarchive

Methods included from Helper::HumanFileSize

#file_to_human_size, #number_to_human_size

Constructor Details

#initialize(file) ⇒ Macos

Returns a new instance of Macos.



24
25
26
# File 'lib/app_info/macos.rb', line 24

def initialize(file)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



15
16
17
# File 'lib/app_info/macos.rb', line 15

def file
  @file
end

Instance Method Details

#app_pathObject



129
130
131
# File 'lib/app_info/macos.rb', line 129

def app_path
  @app_path ||= Dir.glob(File.join(contents, '*.app')).first
end

#archsObject Also known as: architectures



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/app_info/macos.rb', line 74

def archs
  return unless File.exist?(binary_path)

  file = MachO.open(binary_path)
  case file
  when MachO::MachOFile
    [file.cpusubtype]
  else
    file.machos.each_with_object([]) do |arch, obj|
      obj << arch.cpusubtype
    end
  end
end

#binary_pathObject



111
112
113
114
115
116
117
118
119
# File 'lib/app_info/macos.rb', line 111

def binary_path
  return @binary_path if @binary_path

  base_path = File.join(app_path, 'Contents', 'MacOS')
  binary = info['CFBundleExecutable']
  return File.join(base_path, binary) if binary

  @binary_path ||= Dir.glob(File.join(base_path, '*')).first
end

#clear!Object



133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/app_info/macos.rb', line 133

def clear!
  return unless @contents

  FileUtils.rm_rf(@contents)

  @contents = nil
  @app_path = nil
  @binrary_path = nil
  @info_path = nil
  @info = nil
  @icons = nil
end

#contentsObject



146
147
148
# File 'lib/app_info/macos.rb', line 146

def contents
  @contents ||= unarchive(@file, path: 'macos')
end

#distribution_nameObject



44
45
46
# File 'lib/app_info/macos.rb', line 44

def distribution_name
  "#{profile_name} - #{team_name}" if profile_name && team_name
end

#hide_developer_certificatesObject



89
90
91
# File 'lib/app_info/macos.rb', line 89

def hide_developer_certificates
  mobileprovision.delete('DeveloperCertificates') if mobileprovision?
end

#icons(convert: true) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/app_info/macos.rb', line 62

def icons(convert: true)
  return unless icon_file

  data = {
    name: File.basename(icon_file),
    file: icon_file
  }

  convert_icns_to_png(data) if convert
  data
end

#infoObject



121
122
123
# File 'lib/app_info/macos.rb', line 121

def info
  @info ||= InfoPlist.new(info_path)
end

#info_pathObject



125
126
127
# File 'lib/app_info/macos.rb', line 125

def info_path
  @info_path ||= File.join(app_path, 'Contents', 'Info.plist')
end

#mobileprovisionObject



93
94
95
96
97
# File 'lib/app_info/macos.rb', line 93

def mobileprovision
  return unless mobileprovision?

  @mobileprovision ||= MobileProvision.new(mobileprovision_path)
end

#mobileprovision?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/app_info/macos.rb', line 99

def mobileprovision?
  File.exist?(mobileprovision_path)
end

#mobileprovision_pathObject



103
104
105
# File 'lib/app_info/macos.rb', line 103

def mobileprovision_path
  @mobileprovision_path ||= File.join(app_path, 'Contents', 'embedded.provisionprofile')
end

#osObject Also known as: file_type



32
33
34
# File 'lib/app_info/macos.rb', line 32

def os
  Platform::MACOS
end

#release_typeObject



48
49
50
51
52
53
54
55
56
# File 'lib/app_info/macos.rb', line 48

def release_type
  if stored?
    ExportType::APPSTORE
  elsif mobileprovision?
    ExportType::RELEASE
  else
    ExportType::DEBUG
  end
end

#size(human_size: false) ⇒ Object



28
29
30
# File 'lib/app_info/macos.rb', line 28

def size(human_size: false)
  file_to_human_size(@file, human_size: human_size)
end

#store_pathObject



107
108
109
# File 'lib/app_info/macos.rb', line 107

def store_path
  @store_path ||= File.join(app_path, 'Contents', '_MASReceipt', 'receipt')
end

#stored?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/app_info/macos.rb', line 58

def stored?
  File.exist?(store_path)
end