Created
May 25, 2012 20:22
-
-
Save sbuller/2790380 to your computer and use it in GitHub Desktop.
Rugged's Tree objects are unsatisfactory. This eases the pain a bit.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rugged' | |
class TreeProxy < BasicObject | |
def initialize(repo, tree) | |
@repo = repo | |
@tree = tree | |
end | |
def _wrap_yield_(*args) | |
if args.length >= 1 and args[0].class == ::Hash and args[0].has_key? :oid | |
obj = @repo.lookup(args[0][:oid]) | |
args[0] = ::TreeProxy.new(@repo, obj) | |
end | |
@block.call(*args) | |
end | |
def method_missing(*args, &block) | |
@block = block | |
if block | |
block = ::Kernel::lambda {|*proc_args| _wrap_yield_(*proc_args)} | |
end | |
ret = @tree.send(*args, &block) | |
if ret and ret.class == 'Hash' and ret.has_key? :oid | |
obj = @repo.lookup(ret[:oid]) | |
ret = ::TreeProxy.new(@repo, obj) | |
end | |
ret | |
end | |
end | |
def objects | |
repo = Rugged::Repository.new('.') | |
ref = Rugged::Reference.lookup(repo, "refs/heads/t") | |
walker = Rugged::Walker.new(repo) | |
[repo, ref, walker] | |
end | |
repo, ref, walker = objects | |
a = TreeProxy.new(repo, repo.lookup(ref.target).tree) | |
a.each {|t| p t} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay Ruby!!