Class: LontaraUtilities::Git::Branch
- Inherits:
-
Object
- Object
- LontaraUtilities::Git::Branch
- Defined in:
- lib/lontara_utilities/git/branch.rb
Overview
Class Branch used to show all git branches in your project.
Class Method Summary collapse
-
.all ⇒ Object
Show all branches in your project.
-
.current_branch ⇒ Object
Show current running branch in your project.
-
.local ⇒ Object
Show all local branches in your project.
-
.method_missing(method_name, *args) ⇒ Object
Use metaprogramming to define methods for checking current branch using method_missing and plain ruby method.
-
.remote ⇒ Object
Show all remote branches in your project.
- .respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Class Method Details
.all ⇒ Object
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_branch ⇒ Object
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 |
.local ⇒ Object
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 |
.remote ⇒ Object
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
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 |