Class: Mercurial::BranchFactory
- Inherits:
-
Object
- Object
- Mercurial::BranchFactory
- Includes:
- Helper
- Defined in:
- lib/mercurial-ruby/factories/branch_factory.rb
Overview
This class represents a factory for Branch instances.
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Instance of Repository.
Instance Method Summary collapse
-
#active(cmd_options = {}) ⇒ Object
Return an array of Branch instances for all active branches in the repository.
-
#all(cmd_options = {}) ⇒ Object
Return an array of Branch instances for all branches in the repository.
-
#by_name(name, cmd_options = {}) ⇒ Object
Return a Branch instance for a branch with a specified name.
-
#closed(cmd_options = {}) ⇒ Object
Return an array of Branch instances for all closed branches in the repository.
-
#each(cmd_options = {}, &block) ⇒ Object
Run a block for every Branch instance of all branches in the repository.
-
#for_commit(hash_id, cmd_options = {}) ⇒ Object
Return an array of Branch instances where a specified commit exists.
-
#initialize(repository) ⇒ BranchFactory
constructor
A new instance of BranchFactory.
Methods included from Helper
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
#repository ⇒ Object (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(={}) all().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(={}) hg_to_array("branches -c --debug", {}, ) 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')
65 66 67 68 69 |
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 65 def by_name(name, ={}) all().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
54 55 56 57 58 |
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 54 def closed(={}) all().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(={}, &block) all().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')
77 78 79 80 81 |
# File 'lib/mercurial-ruby/factories/branch_factory.rb', line 77 def for_commit(hash_id, ={}) hg_to_array(["log -r 'descendants(?) and head()' --template '\n{branches}'", hash_id], {}, ) do |line| build_with_name_only(line) end.compact.uniq end |