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
# File 'lib/gitt/commands/config.rb', line 18

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

#origin?Boolean

Returns:

  • (Boolean)


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

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

#set(key, value) ⇒ Object



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

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