Module: StateMate::Adapters::TimeMachine

Includes:
StateMate::Adapters
Defined in:
lib/state_mate/adapters/time_machine.rb

Constant Summary collapse

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

Constants included from StateMate::Adapters

API_METHOD_NAMES, DEFAULT_KEY_SEP

Class Method Summary collapse

Methods included from StateMate::Adapters

get, included, register

Class Method Details

.disable_localObject



33
34
35
# File 'lib/state_mate/adapters/time_machine.rb', line 33

def self.disable_local
  Cmds.out! "%{exe} disablelocal", exe: EXE
end

.enable_localObject



29
30
31
# File 'lib/state_mate/adapters/time_machine.rb', line 29

def self.enable_local
  Cmds.out! "%{exe} enablelocal", exe: EXE
end

.local_enabled?Boolean

Returns:

  • (Boolean)


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

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



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

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



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

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