Class: Configural::Config::PlistFile

Inherits:
FileBase
  • Object
show all
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

#path

Class Method Summary collapse

Instance Method Summary collapse

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

.extnamesObject



44
45
46
# File 'lib/configural/config/plist_file.rb', line 44

def self.extnames
  ['.plist']
end

.formatObject



40
41
42
# File 'lib/configural/config/plist_file.rb', line 40

def self.format
  'plist'
end

Instance Method Details

#_loadObject



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

#_saveObject



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