module StateMate::Adapters::Git::Ignore
Adapter for working with `.gitingore` files.
Public Class Methods
read(key, options = {})
click to toggle source
adapter API call that reads a value from the git global config.
@api adapter
@param key [String] the key to read @param options [Hash] unused options to conform to adapter API
@return [String, nil] the git config value, or nil if it's missing.
@raise [SystemCallError] if the key is bad or something else caused the
command to fail.
# 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 = {})
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/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