Class: Avm::Git::Launcher::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/avm/git/launcher/remote.rb

Instance Method Summary collapse

Instance Method Details

#add(url) ⇒ Object

git remote add …



23
24
25
# File 'lib/avm/git/launcher/remote.rb', line 23

def add(url)
  git.execute!('remote', 'add', name, url)
end

#exist?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/avm/git/launcher/remote.rb', line 11

def exist?
  git.execute!('remote').each_line.any? { |line| line.strip == name }
end

#lsObject



15
16
17
18
19
20
# File 'lib/avm/git/launcher/remote.rb', line 15

def ls
  git.execute!(['ls-remote', name]).each_line.to_h do |line|
    x = line.strip.split(/\s+/)
    [x[1], x[0]]
  end
end

#removeObject

git remote rm …



28
29
30
# File 'lib/avm/git/launcher/remote.rb', line 28

def remove
  git.execute!('remote', 'rm', name)
end

#urlObject

git remote get-url …



33
34
35
# File 'lib/avm/git/launcher/remote.rb', line 33

def url
  git.execute!('remote', 'get-url', name).strip.if_present(nil)
end

#url=(url) ⇒ Object

Add or set URL if url is present, remove remote if is blank.



43
44
45
46
47
48
49
50
51
# File 'lib/avm/git/launcher/remote.rb', line 43

def url=(url)
  if exist? && url.blank?
    remove
  elsif exist? && self.url != url
    url_set(url)
  elsif !exist?
    add(url)
  end
end

#url_set(url) ⇒ Object

git remote set-url …



38
39
40
# File 'lib/avm/git/launcher/remote.rb', line 38

def url_set(url)
  git.execute!('remote', 'set-url', name, url)
end