Skip to content

Commit

Permalink
add Rugged::Tree#each_blob and Rugged::Tree#each_tree
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Nov 24, 2011
1 parent 88205df commit 0ab96ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rugged.rb
Expand Up @@ -4,3 +4,4 @@
require 'rugged/version'
require 'rugged/repository'
require 'rugged/walker'
require 'rugged/tree'
13 changes: 13 additions & 0 deletions lib/rugged/tree.rb
@@ -0,0 +1,13 @@
module Rugged
class Tree
# Walks the tree but only yields blobs
def each_blob(mode=:postorder)
self.walk(mode) { |root, e| yield root, e if e[:type] == :blob }
end

# Walks the tree but only yields subtrees
def each_tree(mode=:postorder)
self.walk(mode) { |root, e| yield root, e if e[:type] == :tree }
end
end
end
8 changes: 8 additions & 0 deletions test/tree_test.rb
Expand Up @@ -36,6 +36,14 @@
assert enum.kind_of? Enumerable
end

test "can walk the tree, yielding only trees" do
@tree.each_tree {|root, entry| assert_equal :tree, entry[:type]}
end

test "can walk the tree, yielding only blobs" do
@tree.each_blob {|root, entry| assert_equal :blob, entry[:type]}
end

xtest "can write the tree data" do
end

Expand Down

0 comments on commit 0ab96ab

Please sign in to comment.