Module: StateMate::Adapters::GitConfig
- Includes:
- StateMate::Adapters
- Defined in:
- lib/state_mate/adapters/git_config.rb
Overview
adapter to set global git config options
Constant Summary
Constants included from StateMate::Adapters
API_METHOD_NAMES, DEFAULT_KEY_SEP
Class Method Summary collapse
-
.read(key, options = {}) ⇒ String?
adapter API call that reads a value from the git global config.
-
.write(key, value, options = {}) ⇒ Object
adapter API call that writes a value to the git global config.
Methods included from StateMate::Adapters
Class Method Details
.read(key, options = {}) ⇒ String?
adapter API call that reads a value from the git global config.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/state_mate/adapters/git_config.rb', line 21 def self.read key, = {} 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.
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/state_mate/adapters/git_config.rb', line 50 def self.write key, value, = {} # decide to add or replace based on if the key has a value action = read(key, ).nil? ? '--add' : '--replace' result = Cmds! "git config --global #{ action } %{key} %{value}", key: key, value: value nil end |