class Mercurial::BranchFactory

This class represents a factory for {Mercurial::Branch Branch} instances.

Attributes

repository[R]

Instance of {Mercurial::Repository Repository}.

Public Class Methods

new(repository) click to toggle source
# File lib/mercurial-ruby/factories/branch_factory.rb, line 12
def initialize(repository)
  @repository = repository
end

Public Instance Methods

active(cmd_options={}) click to toggle source

Return an array of {Mercurial::Branch Branch} instances for all active branches in the repository.

Example:

repository.branches.active
# 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={}) click to toggle source

Return an array of {Mercurial::Branch Branch} instances for all branches in the repository.

Example:

repository.branches.all
# 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={}) click to toggle source

Return a {Mercurial::Branch Branch} instance for a branch with a specified name.

Example:

repository.branches.by_name('branchname')
# 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={}) click to toggle source

Return an array of {Mercurial::Branch Branch} instances for all closed branches in the repository.

Example:

repository.branches.closed
# 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) click to toggle source

Run a block for every {Mercurial::Branch Branch} instance of all branches in the repository.

Example:

repository.branches.each {|commit| ... }
# 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={}) click to toggle source

Return an array of {Mercurial::Branch Branch} instances where a specified commit exists. Experimental, doesn't always return a correct list of branches.

Example:

repository.branches.for_commit('291a498f04e9')
# 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={}) click to toggle source

Return an array of {Mercurial::Branch Branch} instances for all inactive branches in the repository.

Example:

repository.branches.inactive
# 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

Private Instance Methods

build(data) click to toggle source
# File lib/mercurial-ruby/factories/branch_factory.rb, line 96
def build(data)
  name, last_commit, status = *data.scan(/([\w\- ]+)\s+\d+:(\w+)\s*\(*(\w*)\)*/).first
  Mercurial::Branch.new(
    repository,
    name,
    :commit => last_commit,
    :status => status
  )
end
build_with_name_only(name) click to toggle source
# File lib/mercurial-ruby/factories/branch_factory.rb, line 106
def build_with_name_only(name)
  name = 'default' if name == ''
  Mercurial::Branch.new(repository, name)
end