class Calasmash::Plist

Does some fun stuff with Xcode plists, calasmash needs to update the Xcode projects plist to trick the simulator into connecting to a sinatra server instead

@author [alexfish]

Attributes

scheme[RW]

Public: the Scheme the plist is related to

Public Class Methods

new(scheme) click to toggle source

Create a new plist instance @param scheme [String] The scheme related to the plist

@return [Plist] A plist instance

# File lib/calasmash/plist.rb, line 23
def initialize(scheme)
  @scheme = scheme
end

Public Instance Methods

execute() click to toggle source

Executes the plist tasks update and clear the old plists

# File lib/calasmash/plist.rb, line 30
def execute
  started
  update
  clear

  completed
end

Private Instance Methods

app_path() click to toggle source

The path to the application

@return [String] The path to the application

# File lib/calasmash/plist.rb, line 97
def app_path
  files = []

  Find.find("#{File.expand_path('~')}/Library/Developer/Xcode/DerivedData/") do |path|
    files << path if path =~ /#{@scheme}.app$/
  end

  files.sort_by { |filename| File.mtime(filename)}.last # get the latest
end
clear() click to toggle source

Clear the existing plist from the iOS simulator

# File lib/calasmash/plist.rb, line 73
def clear
  FileUtils.rm(simulator_plist_path, :force => true)
end
completed() click to toggle source

Output a nice message for completing

# File lib/calasmash/plist.rb, line 51
def completed
  puts "Plist updated 👌"
end
server_ip() click to toggle source

The local IP address of the mock backend server

@return [String] The mock backends IP

# File lib/calasmash/plist.rb, line 81
def server_ip
  Socket.ip_address_list.find {|a| a.ipv4? && !a.ipv4_loopback?}.ip_address
end
server_plist_path() click to toggle source

The path to the server config plist

@return The full path to the server config plist

# File lib/calasmash/plist.rb, line 111
def server_plist_path
  app_path + "/server_config.plist"
end
simulator_plist_path() click to toggle source

The path to the iOS simulators plist

@return [String] The path to the plist

# File lib/calasmash/plist.rb, line 89
def simulator_plist_path
  "#{File.expand_path('~')}/Library/Preferences/com.apple.iphonesimulator.plist"
end
started() click to toggle source

Output a nice message for starting

# File lib/calasmash/plist.rb, line 43
def started
  puts "\nUpdating plist"
  puts "=============="
end
update() click to toggle source

Update the Xcode applications server.plist file with sinatras port and URL

# File lib/calasmash/plist.rb, line 59
def update
  plist_file = CFPropertyList::List.new(:file => server_plist_path)
  plist = CFPropertyList.native_types(plist_file.value)

  plist["url_preference"] = server_ip
  plist["port_preference"] = Calasmash::PORT

  plist_file.value = CFPropertyList.guess(plist)
  plist_file.save(server_plist_path, CFPropertyList::List::FORMAT_XML)
end