class XcodeTool::PlistBuddy
Public Class Methods
new(file)
click to toggle source
# File lib/bean/xcode_tool.rb, line 6 def initialize(file) @plist_file = file end
Public Instance Methods
exit?(key)
click to toggle source
# File lib/bean/xcode_tool.rb, line 21 def exit?(key) system "/usr/libexec/PlistBuddy -c 'Print :#{key}' #{@plist_file} > /dev/null 2>&1" end
method_missing()
click to toggle source
# File lib/bean/xcode_tool.rb, line 14 def method_missing(m, *args) # puts "PlistBuddy call #{m.to_s}, args: #{args}" # return unless m.to_s.include?('=') key = m.to_s format_plist(key, args) end
Private Instance Methods
command(name, key, value, type)
click to toggle source
execute the PlistBuddy
command. Set <Entry> <Value> - Sets the value at Entry to Value Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
Types:
string array dict bool real integer date data
Examples:
Set :CFBundleIdentifier com.apple.plistbuddy Sets the CFBundleIdentifier property to com.apple.plistbuddy Add :CFBundleGetInfoString string "App version 1.0.1" Adds the CFBundleGetInfoString property to the plist Add :CFBundleDocumentTypes: dict Adds a new item of type dict to the CFBundleDocumentTypes array Add :CFBundleDocumentTypes:0 dict Adds the new item to the beginning of the array
# File lib/bean/xcode_tool.rb, line 87 def command(name, key, value, type) return unless %w(Add Set).include?(name) type = name == 'Add' ? " #{type}" : '' system "/usr/libexec/PlistBuddy -c '#{name} :#{key}#{type} #{value}' #{@plist_file}" end
format_plist(key, *args)
click to toggle source
Format the PlistBuddy
commad. Set <Entry> <Value> - Sets the value at Entry to Value Add <Entry> <Type> [<Value>] - Adds Entry to the plist, with value Value
# File lib/bean/xcode_tool.rb, line 30 def format_plist(key, *args) # Example: # team_id => teamID # Replace the `_` with upcase letter. key = key.sub(/_\w/) { |e| e.delete('_').upcase } if key.index('_') # If key contain `id` or `Id`, replace it with `ID` key = key.gsub(/id|Id/, 'ID') if key =~ /id|Id/ _args = args.join().split(", ") key = key.delete('=') if key.index('=') name = exit?(key) ? 'Set' : 'Add' # type = _args.length > 1 ? _args[1] : 'string' case _args.first when String type = 'string' when Numeric type = 'integer' when Array type = 'array' when Hash type = 'dict' when TrueClass type = 'bool' when FalseClass type = 'bool' else type = 'string' end command(name, key, _args.first, type) end