Sha256: f06c99df8e728e8466eefc0358e2a80ca8d7f07797cd65ca91faa15b04bd08ad

Contents?: true

Size: 1.2 KB

Versions: 5

Compression:

Stored size: 1.2 KB

Contents

require 'pp'

require 'CFPropertyList'

require 'nrser'
require 'nrser/exec'

require 'state_mate'

using NRSER

module StateMate::Adapters::TimeMachine
  include StateMate::Adapters
  register 'time_machine'
  
  EXE = '/usr/bin/tmutil'
  PLIST_PATH = '/Library/Preferences/com.apple.TimeMachine.plist'

  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

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

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

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

  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

end # TimeMachine

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
state_mate-0.1.0 lib/state_mate/adapters/time_machine.rb
state_mate-0.0.9 lib/state_mate/adapters/time_machine.rb
state_mate-0.0.8 lib/state_mate/adapters/time_machine.rb
state_mate-0.0.7 lib/state_mate/adapters/time_machine.rb
state_mate-0.0.6 lib/state_mate/adapters/time_machine.rb