Module: Plist4r::Backend::OsxPlist
- Defined in:
- lib/plist4r/backend/osx_plist.rb
Overview
Source: github.com/kballard/osx-plist
This backend only works on MacOSX. It supports everything using a compiled CoreFoundation helper in ext directory, and uses native Cocoa CoreFoundation API calls. This backend invokes CFPropertyListWriteToStream.
Should work for any 10.5 (Leopard), 10.6 (Snow Leopard) Mac OSX distribution. It will do nothing on non-mac platforms (eg Linux etc).
Class Method Summary collapse
- .from_binary(plist) ⇒ Object
- .from_gnustep(plist) ⇒ Object
- .from_string(plist) ⇒ Object
- .from_xml(plist) ⇒ Object
- .require_c_ext ⇒ Object
- .to_binary(plist) ⇒ Object
- .to_fmt(plist, fmt) ⇒ Object
- .to_xml(plist) ⇒ Object
Class Method Details
.from_binary(plist) ⇒ Object
50 51 52 |
# File 'lib/plist4r/backend/osx_plist.rb', line 50 def from_binary plist from_string plist end |
.from_gnustep(plist) ⇒ Object
54 55 56 |
# File 'lib/plist4r/backend/osx_plist.rb', line 54 def from_gnustep plist from_string plist end |
.from_string(plist) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/plist4r/backend/osx_plist.rb', line 24 def from_string plist require_c_ext ruby_object = Plist4r::Backend::OsxPlist.load(plist.from_string, nil) hash_obj = nil if ruby_object.is_a? Hash hash_obj = ruby_object elsif ruby_object hash_obj = { ruby_object.class.to_s => ruby_object } else raise "Conversion tp plist object failed" end hash = ::Plist4r::OrderedHash.new hash.replace hash_obj plist.import_hash hash return plist end |
.from_xml(plist) ⇒ Object
46 47 48 |
# File 'lib/plist4r/backend/osx_plist.rb', line 46 def from_xml plist from_string plist end |
.require_c_ext ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/plist4r/backend/osx_plist.rb', line 16 def require_c_ext core_foundation_framework = "/System/Library/Frameworks/CoreFoundation.framework" unless File.exists? core_foundation_framework raise "CoreFoundation Framework not found. Searched in: #{core_foundation_framework}" end require "#{File.dirname(__FILE__)}/osx_plist/ext/osx_plist" end |
.to_binary(plist) ⇒ Object
70 71 72 |
# File 'lib/plist4r/backend/osx_plist.rb', line 70 def to_binary plist to_fmt plist, :binary1 end |
.to_fmt(plist, fmt) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/plist4r/backend/osx_plist.rb', line 58 def to_fmt plist, fmt require_c_ext string = "" sio = StringIO.new(string, "w") Plist4r::Backend::OsxPlist.dump(sio, plist.to_hash, fmt) return string end |
.to_xml(plist) ⇒ Object
66 67 68 |
# File 'lib/plist4r/backend/osx_plist.rb', line 66 def to_xml plist to_fmt plist, :xml1 end |