Class: FruityBuilder::IOS::Plistutil

Inherits:
Execution
  • Object
show all
Defined in:
lib/fruity_builder/plistutil.rb

Constant Summary

Constants inherited from Execution

Execution::COMMAND_RETRIES, Execution::COMMAND_TIMEOUT

Class Method Summary collapse

Methods inherited from Execution

execute, execute_with_timeout_and_retry

Class Method Details

.get_bundle_id(options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fruity_builder/plistutil.rb', line 7

def self.get_bundle_id(options = {})
  if options.key?(:file)
    xml = IO.read(options[:file])
  elsif options.key?(:xml)
    xml = options[:xml]
  end

  raise PlistutilCommandError.new('No XML was passed') unless xml

  identifiers = xml.scan(/.*CFBundleIdentifier<\/key>\n\t<string>(.*?)<\/string>/)
  identifiers << xml.scan(/.*CFBundleName<\/key>\n\t<string>(.*?)<\/string>/)

  identifiers.flatten.uniq
end

.replace_bundle_id(options = {}) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fruity_builder/plistutil.rb', line 22

def self.replace_bundle_id(options = {})
  if options.key?(:file)
    xml = IO.read(options[:file])
  elsif options.key?(:xml)
    xml = options[:xml]
  end

  raise PlistutilCommandError.new('No XML was passed') unless xml

  replacements = xml.scan(/.*CFBundleIdentifier<\/key>\n\t<string>(.*?)<\/string>/)
  replacements << xml.scan(/.*CFBundleName<\/key>\n\t<string>(.*?)<\/string>/)

  replacements.flatten.uniq.each do |replacement|
    xml = xml.gsub(replacement, options[:new_id])
  end

  IO.write(options[:file], xml) if options.key?(:file)
  xml
end