Class: LontaraUtilities::Git::Branch

Inherits:
Object
  • Object
show all
Defined in:
lib/lontara_utilities/git/branch.rb

Overview

Class Branch used to show all git branches in your project.

Class Method Summary collapse

Class Method Details

.allObject

Show all branches in your project.



13
14
15
# File 'lib/lontara_utilities/git/branch.rb', line 13

def self.all
  `git branch -a`.split("\n").map { |branch| branch.gsub('*', '').strip }
end

.current_branchObject

Show current running branch in your project.



8
9
10
# File 'lib/lontara_utilities/git/branch.rb', line 8

def self.current_branch
  `git rev-parse --abbrev-ref HEAD`.strip
end

.localObject

Show all local branches in your project.



23
24
25
# File 'lib/lontara_utilities/git/branch.rb', line 23

def self.local
  all.reject { |branch| branch.start_with?('remotes') }
end

.method_missing(method_name, *args) ⇒ Object

Use metaprogramming to define methods for checking current branch using method_missing and plain ruby method.



29
30
31
32
33
34
35
# File 'lib/lontara_utilities/git/branch.rb', line 29

def self.method_missing(method_name, *args, &)
  if method_name.to_s.end_with?('?')
    current_branch == method_name.to_s.gsub('?', '')
  else
    super
  end
end

.remoteObject

Show all remote branches in your project.



18
19
20
# File 'lib/lontara_utilities/git/branch.rb', line 18

def self.remote
  all.select { |branch| branch.start_with?('remotes') }
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lontara_utilities/git/branch.rb', line 37

def self.respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('?') || super
end