Class: V::Adapters::Git::Branches
- Inherits:
-
Object
- Object
- V::Adapters::Git::Branches
- Includes:
- Enumerable
- Defined in:
- lib/v/adapters/git/branches.rb
Instance Method Summary collapse
-
#[](name) ⇒ Object
Returns the branch with the given
name
. -
#current ⇒ Object
Returns current branch.
-
#each ⇒ Object
Yields instance of Branch for each branch found in refs/heads.
-
#initialize(environment) ⇒ Branches
constructor
A new instance of Branches.
Constructor Details
#initialize(environment) ⇒ Branches
Returns a new instance of Branches.
82 83 84 85 86 |
# File 'lib/v/adapters/git/branches.rb', line 82 def initialize(environment) @environment = environment root = File.join environment.git_dir, %w[ refs heads ] @glob, @offset = File.join(root, %w[ ** * ]), root.length + 1 end |
Instance Method Details
#[](name) ⇒ Object
Returns the branch with the given name
.
100 101 102 |
# File 'lib/v/adapters/git/branches.rb', line 100 def [](name) Branch.new @environment, name end |
#current ⇒ Object
Returns current branch.
89 90 91 92 93 94 95 96 |
# File 'lib/v/adapters/git/branches.rb', line 89 def current @environment.schedule do head = File.read File.join(@environment.git_dir, 'HEAD') name = head.split(':', 2).last.split('/', 3).last.strip Branch.new @environment, name end end |
#each ⇒ Object
Yields instance of Branch for each branch found in refs/heads.
105 106 107 108 109 110 111 |
# File 'lib/v/adapters/git/branches.rb', line 105 def each @environment.schedule do Dir[ @glob ].each do |path| yield Branch.new(@environment, path[ @offset.. -1 ]) end end end |