Class: Plister::Plist
- Inherits:
-
Object
- Object
- Plister::Plist
- Defined in:
- lib/plister/plist.rb
Constant Summary collapse
- TYPES =
%w(user system host).freeze
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#initialize(domain, type: 'user') ⇒ Plist
constructor
A new instance of Plist.
- #merge(prefs) ⇒ Object
- #preferences ⇒ Object (also: #to_h)
- #preferences=(prefs) ⇒ Object
- #readable? ⇒ Boolean
- #writable? ⇒ Boolean
- #write ⇒ Object
Constructor Details
#initialize(domain, type: 'user') ⇒ Plist
Returns a new instance of Plist.
6 7 8 9 10 |
# File 'lib/plister/plist.rb', line 6 def initialize(domain, type: 'user') @domain = normalize_domain(domain) @type = type.to_s raise ArgumentError, 'Invalid type' unless valid_type? end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
3 4 5 |
# File 'lib/plister/plist.rb', line 3 def domain @domain end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/plister/plist.rb', line 3 def type @type end |
Instance Method Details
#exists? ⇒ Boolean
34 35 36 |
# File 'lib/plister/plist.rb', line 34 def exists? File.exist?(path) end |
#merge(prefs) ⇒ Object
25 26 27 |
# File 'lib/plister/plist.rb', line 25 def merge(prefs) self.preferences = preferences.deep_merge(prefs) end |
#preferences ⇒ Object Also known as: to_h
12 13 14 15 16 |
# File 'lib/plister/plist.rb', line 12 def preferences @preferences ||= CFPropertyList.native_types(list.value) rescue CFFormatError {} end |
#preferences=(prefs) ⇒ Object
19 20 21 22 23 |
# File 'lib/plister/plist.rb', line 19 def preferences=(prefs) list.value = CFPropertyList.guess(prefs, convert_unknown_to_string: true) @preferenes = nil preferences end |
#readable? ⇒ Boolean
42 43 44 |
# File 'lib/plister/plist.rb', line 42 def readable? File.readable?(path) end |
#writable? ⇒ Boolean
38 39 40 |
# File 'lib/plister/plist.rb', line 38 def writable? File.writable?(path) end |