Class: Configural::Config::PlistFile
- Defined in:
- lib/configural/config/plist_file.rb
Overview
Implementation of FileBase using XML PList (Property List) for serialization. This format is most commonly used on Mac OS.
You must have the ‘plist’ library installed to use this format. See: <plist.rubyforge.org/>
Instance Attribute Summary
Attributes inherited from FileBase
Class Method Summary collapse
Instance Method Summary collapse
- #_load ⇒ Object
- #_save ⇒ Object
-
#initialize(*args) ⇒ PlistFile
constructor
A new instance of PlistFile.
Methods inherited from FileBase
#[], #[]=, #clear, #close, #delete, #each, #exists?, get_format_by_extname, get_format_by_name, inherited, #keys, #load, #load!, #save, #save!, #to_hash
Constructor Details
#initialize(*args) ⇒ PlistFile
Returns a new instance of PlistFile.
49 50 51 52 |
# File 'lib/configural/config/plist_file.rb', line 49 def initialize(*args) require 'plist' super end |
Class Method Details
.extnames ⇒ Object
44 45 46 |
# File 'lib/configural/config/plist_file.rb', line 44 def self.extnames ['.plist'] end |
.format ⇒ Object
40 41 42 |
# File 'lib/configural/config/plist_file.rb', line 40 def self.format 'plist' end |
Instance Method Details
#_load ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/configural/config/plist_file.rb', line 54 def _load @data = Plist.parse_xml(path) || {} rescue Errno::ENOENT @data = {} rescue Errno::EACCESS => e warn( "WARNING: Could not load config file #{path.inspect}:\n" + e.inspect + "\nUsing empty dataset instead." ) @data = {} end |
#_save ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/configural/config/plist_file.rb', line 64 def _save require 'fileutils' FileUtils.mkdir_p( File.dirname(path) ) File.open(path, 'w'){ |f| f.write( Plist::Emit.dump(@data) ) } rescue Errno::EACCESS => e warn( "WARNING: Could not save config file #{path.inspect}:\n" + e.inspect ) end |