Class: Mj::Git::Branches
- Inherits:
-
Object
- Object
- Mj::Git::Branches
- Includes:
- Enumerable
- Defined in:
- lib/mj/git/branches.rb
Class Method Summary collapse
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(branches) ⇒ Branches
constructor
A new instance of Branches.
- #length ⇒ Object
- #matching(pattern) ⇒ Object
- #sort_by(&block) ⇒ Object
- #to_local ⇒ Object
- #uniq ⇒ Object
Constructor Details
#initialize(branches) ⇒ Branches
39 40 41 |
# File 'lib/mj/git/branches.rb', line 39 def initialize(branches) @branches = branches end |
Class Method Details
.from_branch_names(branch_names) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mj/git/branches.rb', line 12 def self.from_branch_names(branch_names) branches = branch_names.map do |branch| branch = branch.sub("*", "").strip if branch.start_with?("remotes/") next RemoteBranch.new(branch) end next LocalBranch.new(branch) end new(branches) end |
Instance Method Details
#each(&block) ⇒ Object
43 44 45 |
# File 'lib/mj/git/branches.rb', line 43 def each(&block) @branches.each(&block) end |
#length ⇒ Object
51 52 53 |
# File 'lib/mj/git/branches.rb', line 51 def length @branches.length end |
#matching(pattern) ⇒ Object
55 56 57 |
# File 'lib/mj/git/branches.rb', line 55 def matching(pattern) self.class.new(@branches.select { |branch| branch.name.match?(pattern) }) end |
#sort_by(&block) ⇒ Object
47 48 49 |
# File 'lib/mj/git/branches.rb', line 47 def sort_by(&block) self.class.new(@branches.sort_by(&block)) end |
#to_local ⇒ Object
26 27 28 |
# File 'lib/mj/git/branches.rb', line 26 def to_local self.class.new(map(&:to_local)) end |
#uniq ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/mj/git/branches.rb', line 30 def uniq branches = {} each do |branch| branches[branch.name] ||= branch end self.class.new(branches.values) end |