Sha256: f6236a2cdd3413dd9b7346ec5dd1dbc8579ace679ff17570999f9dc0405878da

Contents?: true

Size: 1.45 KB

Versions: 9

Compression:

Stored size: 1.45 KB

Contents

require 'cmds'

require 'state_mate'

# adapter to set global git config options
module StateMate::Adapters::SCUtil
  include StateMate::Adapters
  register 'scutil'

  # @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.
  #
  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 # ::read


  # @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
  #
  def self.write key, value, options = {}
    Cmds! "sudo scutil --set %{key} %{value}",
          key: key,
          value: value
    nil
  end # ::write
end # SCUtil

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
state_mate-0.1.4 lib/state_mate/adapters/scutil.rb
state_mate-0.1.3 lib/state_mate/adapters/scutil.rb
state_mate-0.1.2 lib/state_mate/adapters/scutil.rb
state_mate-0.1.1 lib/state_mate/adapters/scutil.rb
state_mate-0.1.0 lib/state_mate/adapters/scutil.rb
state_mate-0.0.9 lib/state_mate/adapters/scutil.rb
state_mate-0.0.8 lib/state_mate/adapters/scutil.rb
state_mate-0.0.7 lib/state_mate/adapters/scutil.rb
state_mate-0.0.6 lib/state_mate/adapters/scutil.rb