Class: GitProc::GitBranches
- Inherits:
-
Object
- Object
- GitProc::GitBranches
- Includes:
- Enumerable
- Defined in:
- lib/git-process/git_branches.rb
Instance Method Summary collapse
- #<<(item) ⇒ Object
- #[](branch_name) ⇒ Object
- #current ⇒ Object
- #each(&block) ⇒ Object
- #include?(branch_name) ⇒ Boolean
-
#initialize(lib, opt = {}) ⇒ GitBranches
constructor
A new instance of GitBranches.
- #names ⇒ Object
- #parking ⇒ Object
Constructor Details
#initialize(lib, opt = {}) ⇒ GitBranches
Returns a new instance of GitBranches.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/git-process/git_branches.rb', line 22 def initialize(lib, opt = {}) @lib = lib branch_opts = {:no_color => true} if opt[:remote] branch_opts[:remote] = true elsif opt[:local] branch_opts[:local] = true else branch_opts[:all] = true end branch_lines = lib.branch(nil, branch_opts).split("\n") @items = SortedSet.new branch_lines.each do |bl| @items << GitBranch.new(bl[2..-1], bl[0..0] == '*', lib) end end |
Instance Method Details
#<<(item) ⇒ Object
40 41 42 |
# File 'lib/git-process/git_branches.rb', line 40 def <<(item) @items << item end |
#[](branch_name) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/git-process/git_branches.rb', line 70 def [](branch_name) branch_name = current.name if branch_name == 'HEAD' br = @items.find { |b| b.name == branch_name } if br.nil? and branch_name !~ /origin\// and branch_name != '_parking_' @lib.logger.warn { "Could not find '#{branch_name}' in #{@items.map { |i| i.name }.join(',')}" } end br end |
#current ⇒ Object
55 56 57 |
# File 'lib/git-process/git_branches.rb', line 55 def current @items.find { |b| b.current? } end |
#each(&block) ⇒ Object
45 46 47 |
# File 'lib/git-process/git_branches.rb', line 45 def each(&block) @items.each { |b| block.call(b) } end |
#include?(branch_name) ⇒ Boolean
65 66 67 |
# File 'lib/git-process/git_branches.rb', line 65 def include?(branch_name) @items.find { |b| b.name == branch_name } != nil end |
#names ⇒ Object
50 51 52 |
# File 'lib/git-process/git_branches.rb', line 50 def names @items.map { |b| b.name } end |
#parking ⇒ Object
60 61 62 |
# File 'lib/git-process/git_branches.rb', line 60 def parking @items.find { |b| b.name == '_parking_' } end |