Class: GitRecent::BranchLister

Inherits:
Object
  • Object
show all
Defined in:
lib/git_recent/branch_lister.rb

Instance Method Summary collapse

Constructor Details

#initialize(reflog_iterator = GitRecent::ReflogIterator.new, local_branches = GitRecent::LocalBranchReader.local_branches_excluding_current) ⇒ BranchLister

Returns a new instance of BranchLister.



9
10
11
12
13
# File 'lib/git_recent/branch_lister.rb', line 9

def initialize(reflog_iterator=GitRecent::ReflogIterator.new,
               local_branches=GitRecent::LocalBranchReader.local_branches_excluding_current)
  @reflog_iterator = reflog_iterator
  @local_branches = local_branches
end

Instance Method Details

#branch_names(max) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/git_recent/branch_lister.rb', line 15

def branch_names(max)
  recent_branches = {}

  reflog_iterator.each do |reflog_line|
    to_branch = reflog_line.to_branch
    recent_branches[to_branch] = true if should_include_branch? to_branch

    return recent_branches.keys if recent_branches.keys.length == max

    from_branch = reflog_line.from_branch
    recent_branches[from_branch] = true if should_include_branch? from_branch

    return recent_branches.keys if recent_branches.keys.length == max
  end

  recent_branches.keys
end