Class: IOSDevTools::ApplicationBundle

Inherits:
Object
  • Object
show all
Defined in:
lib/ios_dev_tools/model/application_bundle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_or_folder_location) {|_self| ... } ⇒ ApplicationBundle

Returns a new instance of ApplicationBundle.

Yields:

  • (_self)

Yield Parameters:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 20

def initialize file_or_folder_location

  raise "Application bundle \"#{file_or_folder_location}\" doesn't exist" if not File.exists? file_or_folder_location

  @is_application_folder=File.directory?(file_or_folder_location) && file_or_folder_location.end_with?(".app")
  if not @is_application_folder
    @is_valid_zip_archive=`file #{file_or_folder_location}`.include? "Zip archive data"
    raise "[#{file_or_folder_location}] is not a valid application archive" if not @is_valid_zip_archive
  end

  yield self if block_given?

  @src_location=file_or_folder_location
  @temp_folder||="temp"

  if not @is_application_folder
    # wipe out temp folder
    `rm -Rf #{temp_folder}/Payload 2>&1 > /dev/null`
    # unzip application bundle
    `unzip -q "#{@src_location}" -d #{@temp_folder}`
    # point to unzipped location
    @location=Dir.glob("#{@temp_folder}/Payload/*")[0]
  else
    @location=@src_location
  end

  @application_name=Pathname.new(@location).basename
  @info_plist=InfoPlist.new "#{@location}/Info.plist"

end

Instance Attribute Details

#application_nameObject

Returns the value of attribute application_name.



17
18
19
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 17

def application_name
  @application_name
end

#info_plistObject

Returns the value of attribute info_plist.



18
19
20
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 18

def info_plist
  @info_plist
end

#is_application_folderObject

Returns the value of attribute is_application_folder.



11
12
13
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 11

def is_application_folder
  @is_application_folder
end

#is_valid_zip_archiveObject

Returns the value of attribute is_valid_zip_archive.



12
13
14
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 12

def is_valid_zip_archive
  @is_valid_zip_archive
end

#locationObject

Returns the value of attribute location.



14
15
16
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 14

def location
  @location
end

#plist_buddy_cmdObject

Returns the value of attribute plist_buddy_cmd.



16
17
18
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 16

def plist_buddy_cmd
  @plist_buddy_cmd
end

#src_locationObject

Returns the value of attribute src_location.



13
14
15
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 13

def src_location
  @src_location
end

#temp_folderObject

Returns the value of attribute temp_folder.



15
16
17
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 15

def temp_folder
  @temp_folder
end

Instance Method Details

#current_identityObject



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 63

def current_identity

  invalid_signature=`codesign -d -vv "#{@location}" 2>&1`.include? "invalid signature"
  return "Invalid signature" if invalid_signature

  codesign_output=`codesign -d -vv "#{@location}" 2>&1 | grep "Authority"`
  info=codesign_output.lines.first
  return info.strip.split("=")[1] if info

  return nil

end

#package_to_ipa(ipa_file_location) ⇒ Object



76
77
78
79
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 76

def package_to_ipa ipa_file_location
  return if not ipa_file_location
  `(cd #{@temp_folder} && zip -qr ../temp.ipa *) && mv temp.ipa "#{ipa_file_location}"`
end

#set_provisioning_profile(new_provisioning_profile_location) ⇒ Object



53
54
55
56
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 53

def set_provisioning_profile new_provisioning_profile_location
  return if not new_provisioning_profile_location
  `cp "#{new_provisioning_profile_location}" "#{@location}/embedded.mobileprovision"`
end

#sign_with_identity(new_identity) ⇒ Object



58
59
60
61
# File 'lib/ios_dev_tools/model/application_bundle.rb', line 58

def sign_with_identity new_identity
  return if not new_identity
  `/usr/bin/codesign -f -s "#{new_identity}" --resource-rules="#{@location}/ResourceRules.plist" "#{@location}" 2>&1`
end