Class: Git::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/Git/Remote.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, url:) ⇒ Remote

Returns a new instance of Remote.



72
73
74
75
# File 'lib/Git/Remote.rb', line 72

def initialize(name:, url:)
  @name = name
  @url = url
end

Instance Attribute Details

#nameObject

class << self



69
70
71
# File 'lib/Git/Remote.rb', line 69

def name
  @name
end

#urlObject

Returns the value of attribute url.



70
71
72
# File 'lib/Git/Remote.rb', line 70

def url
  @url
end

Class Method Details

.add(remote_name, remote_url) ⇒ Object



51
52
53
# File 'lib/Git/Remote.rb', line 51

def add(remote_name, remote_url)
  system add_command(remote_name, remote_url)
end

.add_command(remote_name, remote_url) ⇒ Object



47
48
49
# File 'lib/Git/Remote.rb', line 47

def add_command(remote_name, remote_url)
  ['git remote add', remote_name, remote_url].join(' ')
end

.allObject



37
38
39
40
41
# File 'lib/Git/Remote.rb', line 37

def all
  remote_output.split("\n").collect do |remote|
    parse_line(remote)
  end.uniq{|remote| remote.name}
end

.exist?(remote_name) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/Git/Remote.rb', line 63

def exist?(remote_name)
  !!find(remote_name)
end

.find(remote_name) ⇒ Object



43
44
45
# File 'lib/Git/Remote.rb', line 43

def find(remote_name)
  all.detect{|remote| remote.name == remote_name}
end

.parse_line(remote_output_line) ⇒ Object



28
29
30
31
# File 'lib/Git/Remote.rb', line 28

def parse_line(remote_output_line)
  name, url = remote_output_line.split
  new(name: name, url: url)
end

.remote_outputObject



33
34
35
# File 'lib/Git/Remote.rb', line 33

def remote_output
  `git remote --verbose`
end

.remove(remote_name, remote_url) ⇒ Object



59
60
61
# File 'lib/Git/Remote.rb', line 59

def remove(remote_name, remote_url)
  system remove_command(remote_name)
end

.remove_command(remote_name) ⇒ Object



55
56
57
# File 'lib/Git/Remote.rb', line 55

def remove_command(remote_name)
  ['git remote remove', remote_name].join(' ')
end

Instance Method Details

#removeObject Also known as: delete



77
78
79
# File 'lib/Git/Remote.rb', line 77

def remove
  self.class.remove(@name, @url)
end

#to_sObject



82
83
84
# File 'lib/Git/Remote.rb', line 82

def to_s
  "#{@name} #{@url}"
end