module StateMate::Adapters::SCUtil

adapter to set global git config options

Public Class Methods

read(key, options = {}) click to toggle source

@api adapter

adapter API call that reads a value from scutil.

@param 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).

@param options [Hash] unused options to conform to adapter API

@return [String, nil] the scutil value, or `nil` if not set.

@raise [SystemCallError] if the command failed.

# 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 = {}) click to toggle source

@api adapter

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

@param key [String] the key to write @param value [String] the value to write @param options [Hash] unused options to conform to adapter API

@return nil

# 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