Class: Gitt::Commands::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/gitt/commands/config.rb

Overview

A Git config command wrapper.

Instance Method Summary collapse

Constructor Details

#initialize(shell: SHELL) ⇒ Config

Returns a new instance of Config.



12
13
14
# File 'lib/gitt/commands/config.rb', line 12

def initialize shell: SHELL
  @shell = shell
end

Instance Method Details

#callObject



16
# File 'lib/gitt/commands/config.rb', line 16

def call(*, **) = shell.call("config", *, **)

#get(key, fallback = Core::EMPTY_STRING) ⇒ Object



18
19
20
21
22
# File 'lib/gitt/commands/config.rb', line 18

def get(key, fallback = Core::EMPTY_STRING, *, **)
  shell.call("config", "--get", key, *, **)
       .fmap(&:chomp)
       .or { |error| block_given? ? yield(error) : Success(fallback) }
end

#origin?Boolean

Returns:

  • (Boolean)


24
# File 'lib/gitt/commands/config.rb', line 24

def origin? = !get("remote.origin.url").value_or(Core::EMPTY_STRING).empty?

#set(key, value) ⇒ Object



26
# File 'lib/gitt/commands/config.rb', line 26

def set(key, value, *, **) = shell.call("config", "--add", key, value, *, **).fmap { value }