Module: StateMate::Adapters::TimeMachine

Defined in:
lib/state_mate/adapters/time_machine.rb

Constant Summary collapse

EXE =
'/usr/bin/tmutil'
PLIST_PATH =
'/Library/Preferences/com.apple.TimeMachine.plist'

Class Method Summary collapse

Class Method Details

.disable_localObject



31
32
33
# File 'lib/state_mate/adapters/time_machine.rb', line 31

def self.disable_local
  NRSER::Exec.run "%{exe} disablelocal", exe: EXE
end

.enable_localObject



27
28
29
# File 'lib/state_mate/adapters/time_machine.rb', line 27

def self.enable_local
  NRSER::Exec.run "%{exe} enablelocal", exe: EXE
end

.local_enabled?Boolean



17
18
19
20
21
22
23
24
25
# File 'lib/state_mate/adapters/time_machine.rb', line 17

def self.local_enabled?
  # seems to change the key
  #
  #     /Library/Preferences/com.apple.TimeMachine.plist:MobileBackups
  # 
  plist = CFPropertyList::List.new file: PLIST_PATH
  data = CFPropertyList.native_types plist.value
  data['MobileBackups']
end

.read(key, options = {}) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/state_mate/adapters/time_machine.rb', line 35

def self.read key, options = {}
  case key
  when 'local_backups'
    local_enabled?
  else
   raise "bad key: #{ key.inspect }"
  end
end

.write(key, value, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/state_mate/adapters/time_machine.rb', line 44

def self.write key, value, options = {}
  case key
  when 'local_backups'
    case value
    when true
      enable_local
    when false
      disable_local
    else
      raise "bad value: #{ value.inspect }"
    end
  else
    raise "bad key: #{ key.inspect }"
  end
end