Class: Gitw::Git::RemoteRef

Inherits:
Object
  • Object
show all
Defined in:
lib/gitw/git/remote_ref.rb

Overview

encapsulate git remote reference entry

Constant Summary collapse

REMOTE_LINE_RE =
/^(?<name>\w+)
\s+
(?<url>[^\s]+)
\s+
\((?<mode>fetch|push)\)$/x.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, fetch: nil, push: nil) ⇒ RemoteRef

Returns a new instance of RemoteRef.



52
53
54
55
56
# File 'lib/gitw/git/remote_ref.rb', line 52

def initialize(name, fetch: nil, push: nil)
  @name = name
  @fetch = fetch
  @push = push
end

Instance Attribute Details

#fetchObject (readonly)

Returns the value of attribute fetch.



50
51
52
# File 'lib/gitw/git/remote_ref.rb', line 50

def fetch
  @fetch
end

#nameObject (readonly)

Returns the value of attribute name.



50
51
52
# File 'lib/gitw/git/remote_ref.rb', line 50

def name
  @name
end

#pushObject (readonly)

Returns the value of attribute push.



50
51
52
# File 'lib/gitw/git/remote_ref.rb', line 50

def push
  @push
end

Class Method Details

.parse(ref_line) ⇒ Object



71
72
73
74
75
76
# File 'lib/gitw/git/remote_ref.rb', line 71

def self.parse(ref_line)
  return unless (match = REMOTE_LINE_RE.match(ref_line.strip))

  new(match[:name],
      match[:mode].to_sym => match[:url])
end

Instance Method Details

#update(other_ref) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/gitw/git/remote_ref.rb', line 62

def update(other_ref)
  return self if self == other_ref
  return self if name != other_ref.name

  @fetch = other_ref.fetch || @fetch
  @push = other_ref.push || @push
  self
end

#urlObject



58
59
60
# File 'lib/gitw/git/remote_ref.rb', line 58

def url
  fetch || push
end