Module: StateMate::Adapters::Git::Ignore

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

Overview

Adapter for working with .gitingore files.

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 the git global config.

Parameters:

  • key (String)

    the key to read

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

    unused options to conform to adapter API

Returns:

  • (String, nil)

    the git config value, or nil if it's missing.

Raises:

  • (SystemCallError)

    if the key is bad or something else caused the command to fail.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/state_mate/adapters/git/ignore.rb', line 46

def self.read key, options = {}
  result = Cmds "git config --global --get %{key}", key: key
  
  # if the command succeeded the result is the output
  # (minus trailing newline)
  if result.ok?
    result.out.chomp
  
  # if it errored with no output then the key is missing
  elsif result.err == ''
    nil
  
  # otherwise, raise an error
  else
    result.assert
  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



75
76
77
78
79
80
81
82
83
84
# File 'lib/state_mate/adapters/git/ignore.rb', line 75

def self.write key, value, options = {}
  # decide to add or replace based on if the key has a value
  action = read(key, options).nil? ? '--add' : '--replace'

  result = Cmds!  "git config --global #{ action } %{key} %{value}",
                  key: key,
                  value: value
  
  nil
end