Method: Jamf::Utility#parse_plist

Defined in:
lib/jamf/utility.rb

#parse_plist(plist, symbol_keys: false) ⇒ Object

Parse a plist into a Ruby data structure. The plist parameter may be a String containing an XML plist, or a path to a plist file, or it may be a Pathname object pointing to a plist file. The plist files may be XML or binary.

Parameters:

  • plist (Pathname, String)

    the plist XML, or the path to a plist file

  • symbol_keys (Boolean) (defaults to: false)

    should any Hash keys in the result be converted into Symbols rather than remain as Strings?

Returns:

  • (Object)

    the parsed plist as a ruby hash,array, etc.



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'lib/jamf/utility.rb', line 335

def parse_plist(plist, symbol_keys: false)
  require 'cfpropertylist'

  # did we get a string of xml, or a string pathname?
  case plist
  when String
    return CFPropertyList.native_types(CFPropertyList::List.new(data: plist).value, symbol_keys) if plist.include? '</plist>'

    plist = Pathname.new plist
  when Pathname
    true
  else
    raise ArgumentError, 'Argument must be a path (as a Pathname or String) or a String of XML'
  end # case plist

  # if we're here, its a Pathname
  raise Jamf::MissingDataError, "No such file: #{plist}" unless plist.file?

  CFPropertyList.native_types(CFPropertyList::List.new(file: plist).value, symbol_keys)
end