Module: StateMate::Adapters::SCUtil

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

Overview

adapter to set global git config options

Constant Summary

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

.read(key, options = {}) ⇒ String?

adapter API call that reads a value from scutil.

Parameters:

  • key (String)

    the key to read. from man scutil:

    Supported preferences include:

      ComputerName   The user-friendly name for the system.
    
      LocalHostName  The local (Bonjour) host name.
    
      HostName       The name associated with hostname(1) and gethostname(3).
    
  • options (Hash) (defaults to: {})

    unused options to conform to adapter API

Returns:

  • (String, nil)

    the scutil value, or nil if not set.

Raises:

  • (SystemCallError)

    if the command failed.



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/state_mate/adapters/scutil.rb', line 30

def self.read key, options = {}
  result = Cmds "scutil --get %{key}", key: key
  if result.ok?
    result.out.chomp
  else
    if result.err.match /^#{ key }\:\ not set/
      nil
    else
      result.assert
    end
  end
end

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

adapter API call that writes a value to the git global config.

Parameters:

  • key (String)

    the key to write

  • value (String)

    the value to write

  • options (Hash) (defaults to: {})

    unused options to conform to adapter API

Returns:

  • nil



54
55
56
57
58
59
# File 'lib/state_mate/adapters/scutil.rb', line 54

def self.write key, value, options = {}
  Cmds! "sudo scutil --set %{key} %{value}",
        key: key,
        value: value
  nil
end