Class: Mercurial::BranchFactory

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/mercurial-ruby/factories/branch_factory.rb

Overview

This class represents a factory for Branch instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#hg, #hg_to_array, #shell

Constructor Details

#initialize(repository) ⇒ BranchFactory

Returns a new instance of BranchFactory.



12
13
14
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 12

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Instance of Repository.



10
11
12
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 10

def repository
  @repository
end

Instance Method Details

#active(cmd_options = {}) ⇒ Object

Return an array of Branch instances for all active branches in the repository.

Example:

repository.branches.active


43
44
45
46
47
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 43

def active(cmd_options={})
  all(cmd_options).find_all do |b|
    b.active?
  end
end

#all(cmd_options = {}) ⇒ Object

Return an array of Branch instances for all branches in the repository.

Example:

repository.branches.all


21
22
23
24
25
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 21

def all(cmd_options={})
  hg_to_array("branches -c --debug", {}, cmd_options) do |line|
    build(line)
  end
end

#by_name(name, cmd_options = {}) ⇒ Object

Return a Branch instance for a branch with a specified name.

Example:

repository.branches.by_name('branchname')


76
77
78
79
80
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 76

def by_name(name, cmd_options={})
  all(cmd_options).find do |b|
    b.name == name
  end
end

#closed(cmd_options = {}) ⇒ Object

Return an array of Branch instances for all closed branches in the repository.

Example:

repository.branches.closed


65
66
67
68
69
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 65

def closed(cmd_options={})
  all(cmd_options).find_all do |b|
    b.closed?
  end
end

#each(cmd_options = {}, &block) ⇒ Object

Run a block for every Branch instance of all branches in the repository.

Example:

repository.branches.each {|commit| ... }


32
33
34
35
36
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 32

def each(cmd_options={}, &block)
  all(cmd_options).each do |branch|
    block.call(branch)
  end
end

#for_commit(hash_id, cmd_options = {}) ⇒ Object

Return an array of Branch instances where a specified commit exists. Experimental, doesn’t always return a correct list of branches.

Example:

repository.branches.for_commit('291a498f04e9')


88
89
90
91
92
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 88

def for_commit(hash_id, cmd_options={})
  hg_to_array(["log -r 'descendants(?) and head()' --template '\n{branches}'", hash_id], {}, cmd_options) do |line|
    build_with_name_only(line)
  end.compact.uniq
end

#inactive(cmd_options = {}) ⇒ Object

Return an array of Branch instances for all inactive branches in the repository.

Example:

repository.branches.inactive


54
55
56
57
58
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 54

def inactive(cmd_options={})
  all(cmd_options).find_all do |b|
    b.inactive?
  end
end