Module: StateMate::Adapters::SCUtil

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

Overview

adapter to set global git config options

Class Method Summary collapse

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.



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

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



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

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