Class: Git::Branch
- Inherits:
-
Object
show all
- Defined in:
- lib/Git/Branch.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name = nil, **args) ⇒ Branch
Returns a new instance of Branch.
106
107
108
109
|
# File 'lib/Git/Branch.rb', line 106
def initialize(name = nil, **args)
@name = name
@remote = args[:remote]
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
127
128
129
130
131
|
# File 'lib/Git/Branch.rb', line 127
def method_missing(method_name, *args, &block)
if method_name.to_s =~ /\?$/ && !self.class.instance_methods.include?(method_name)
@name == method_name.to_s.sub('?', '')
end
end
|
Instance Attribute Details
#name ⇒ Object
103
104
105
|
# File 'lib/Git/Branch.rb', line 103
def name
@name
end
|
#remote ⇒ Object
Returns the value of attribute remote.
104
105
106
|
# File 'lib/Git/Branch.rb', line 104
def remote
@remote
end
|
Class Method Details
.all ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/Git/Branch.rb', line 77
def all
result = branch_output.split("\n").collect do |branch|
if @switches.include?('--remote')
branch_parts = branch.split('/')
remote, branch_name = branch_parts.first.sub('*', '').strip, branch_parts.all_but_first.join('/')
new(branch_name, remote: remote)
else
branch_name = branch.sub('*', '').strip
new(branch_name)
end
end
result
end
|
.branch_output ⇒ Object
73
74
75
|
# File 'lib/Git/Branch.rb', line 73
def branch_output
`#{command_string}`
end
|
.command_string ⇒ Object
67
68
69
70
71
|
# File 'lib/Git/Branch.rb', line 67
def command_string
command_string = ['git branch', @switches.join(' ')].join(' ').strip
@switches = []
command_string
end
|
.current ⇒ Object
Also known as:
head
91
92
93
94
|
# File 'lib/Git/Branch.rb', line 91
def current
branch_name = branch_output.split("\n").detect{|branch| branch =~ /\*/}.sub('*', '').strip
new(branch_name)
end
|
.default ⇒ Object
97
98
99
|
# File 'lib/Git/Branch.rb', line 97
def default
`git rev-parse --abbrev-ref origin/HEAD`.strip.split('/').last
end
|
.local ⇒ Object
53
54
55
|
# File 'lib/Git/Branch.rb', line 53
def local
self
end
|
.merged ⇒ Object
62
63
64
65
|
# File 'lib/Git/Branch.rb', line 62
def merged
@switches << '--merged'
self
end
|
.remote ⇒ Object
57
58
59
60
|
# File 'lib/Git/Branch.rb', line 57
def remote
@switches << '--remote'
self
end
|
Instance Method Details
#merged? ⇒ Boolean
111
112
113
114
115
116
117
|
# File 'lib/Git/Branch.rb', line 111
def merged?
if @remote
self.class.remote.merged.all.collect{|branch| branch.name}.include?(@remote + '/' + @name)
else
self.class.merged.all.collect{|branch| branch.name}.include?(@name)
end
end
|
#to_s ⇒ Object
119
120
121
122
123
124
125
|
# File 'lib/Git/Branch.rb', line 119
def to_s
if @remote
@remote + '/' + @name
else
@name
end
end
|