Class: MacAppSync::Defaults::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/mac_app_sync/defaults/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain) ⇒ Store



8
9
10
# File 'lib/mac_app_sync/defaults/store.rb', line 8

def initialize(domain)
  @domain = domain
end

Instance Attribute Details

#domainObject (readonly)

Returns the value of attribute domain.



6
7
8
# File 'lib/mac_app_sync/defaults/store.rb', line 6

def domain
  @domain
end

Instance Method Details

#plistObject



20
21
22
# File 'lib/mac_app_sync/defaults/store.rb', line 20

def plist
  @plist ||= CFPropertyList::List.new(file: plist_path)
end

#plist_pathObject



33
34
35
# File 'lib/mac_app_sync/defaults/store.rb', line 33

def plist_path
  @plist_path ||= prefs_file_path || container_file_path
end

#set(key, value) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/mac_app_sync/defaults/store.rb', line 24

def set(key, value)
  new_value = PlistConverter.to_plist(value)
  current_value = plist.value.value[key]

  if Comparator.different?(current_value, new_value)
    plist.value.value[key] = new_value
  end
end

#to_binaryObject



16
17
18
# File 'lib/mac_app_sync/defaults/store.rb', line 16

def to_binary
  plist.to_str(CFPropertyList::List::FORMAT_XML)
end

#valuesObject



12
13
14
# File 'lib/mac_app_sync/defaults/store.rb', line 12

def values
  PlistConverter.to_ruby(plist.value)
end