Sha256: 97eb9577db90896a18984acb659f87c74958ddfbe6cd0633d235b1ae43dc4012
Contents?: true
Size: 1.3 KB
Versions: 44
Compression:
Stored size: 1.3 KB
Contents
require 'cfpropertylist' module Nixenvironment class Plist FORMAT_BINARY = CFPropertyList::List::FORMAT_BINARY FORMAT_XML = CFPropertyList::List::FORMAT_XML # FORMAT_PLAIN = CFPropertyList::List::FORMAT_PLAIN FORMAT_AUTO = CFPropertyList::List::FORMAT_AUTO def self.from_file(path) new(CFPropertyList::List.new(:file => path)) end def self.from_hash(hash) plist = CFPropertyList::List.new plist.value = CFPropertyList.guess(hash) plist.format = FORMAT_XML new(plist) end def self.from_str(str) plist = CFPropertyList::List.new plist.load_str(str) new(plist) end def initialize(plist) @plist = plist @path = @plist.filename @data = CFPropertyList.native_types(@plist.value) end def [](key) @data[key] end def []=(key, value) @data[key] = value @plist.value = CFPropertyList.guess(@data, :convert_unknown_to_string => true) end def save(path = nil, format = nil, formatted = true) path ||= @path raise 'Path to save plist is not specified!' unless path @plist.save(path, format, :formatted => formatted) end def to_s(format = FORMAT_AUTO, formatted = true) @plist.to_str(format, :formatted => formatted) end end end
Version data entries
44 entries across 44 versions & 1 rubygems