Skip to content

Commit

Permalink
reference simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Sep 3, 2010
1 parent a270d51 commit 6244a46
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/gitrb/gitobject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(options = {})
@id = options[:id]
end

def object
def git_object
self
end

Expand Down
13 changes: 3 additions & 10 deletions lib/gitrb/reference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def initialize(properties = {})

def method_missing(name, *args, &block)
if @object
unless name == :to_ary || name == :to_str
# Ruby 1.9 uses the presence of the to_ary and to_str methods to determine if an object is coercable.
# If we create these methods, Ruby will incorrectly think that the object can be converted to an array.
if @object.respond_to? name
instance_eval %{def self.#{name}(*args, &block); @object.send("#{name}", *args, &block); end}
end
@object.send(name, *args, &block)
Expand All @@ -21,17 +19,12 @@ def method_missing(name, *args, &block)
@properties[name]
elsif @properties.include?(name.to_s)
@properties[name.to_s]
elsif object
method_missing(name, *args, &block)
else
super
@object = repository.get(id)
method_missing(name, *args, &block)
end
end

def object
@object ||= repository.get(id)
end

def resolved?
@object != nil
end
Expand Down
1 change: 0 additions & 1 deletion lib/gitrb/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,3 @@ def ord
end
end
end

10 changes: 5 additions & 5 deletions test/repository_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@

repo.refresh

repo.root['x'].object.should.be.kind_of(Gitrb::Tree)
repo.root['y'].object.should.be.kind_of(Gitrb::Tree)
repo.root['x'].git_object.should.be.kind_of(Gitrb::Tree)
repo.root['y'].git_object.should.be.kind_of(Gitrb::Tree)

repo.root['x']['a'].data.should.equal 'Hello'
repo.root['y']['b'].data.should.equal 'World'
Expand Down Expand Up @@ -164,8 +164,8 @@
repo.root['x/a'] = Gitrb::Blob.new(:data => 'Added')
end

a = ls_tree(repo.root['a'].object.id)
x = ls_tree(repo.root['x'].object.id)
a = ls_tree(repo.root['a'].id)
x = ls_tree(repo.root['x'].id)

a.should.equal [["100644", "blob", "b653cf27cef08de46da49a11fa5016421e9e3b32", "b"]]
x.should.equal [["100644", "blob", "87d2b203800386b1cc8735a7d540a33e246357fa", "a"]]
Expand Down Expand Up @@ -249,7 +249,7 @@
tag = repo.get(id)

tag.tagtype.should.equal 'commit'
tag.object.object.should.equal repo.head
tag.object.git_object.should.equal repo.head
tag.tagger.name.should.equal user.name
tag.tagger.email.should.equal user.email
tag.message.should =~ /message/
Expand Down

0 comments on commit 6244a46

Please sign in to comment.