Skip to content

Commit

Permalink
helper methods to get actual Objects, not just information about them
Browse files Browse the repository at this point in the history
avoids having to have the caller keep looking up objects directly from
the repo
  • Loading branch information
ccutrer committed Jun 3, 2019
1 parent 33873e5 commit 4b0d505
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/rugged/diff/delta.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def typechange?
status == :typechange
end

def old_blob
owner.owner.lookup(old_file[:oid]) unless added?
end

def new_blob
owner.owner.lookup(new_file[:oid]) unless deleted?
end

def inspect
"#<#{self.class.name}:#{object_id} {old_file: #{old_file.inspect}, new_file: #{new_file.inspect}, similarity: #{similarity.inspect}, status: #{status.inspect}>"
end
Expand Down
5 changes: 5 additions & 0 deletions lib/rugged/tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ def diff(other = nil, options = nil)
Tree.diff(repo, self, other, options)
end

def lookup(entry_id)
entry = get_entry(entry_id)
owner.lookup(entry[:oid]) if entry
end

def inspect
data = "#<Rugged::Tree:#{object_id} {oid: #{oid}}>\n"
self.each { |e| data << " <\"#{e[:name]}\" #{e[:oid]}>\n" }
Expand Down

0 comments on commit 4b0d505

Please sign in to comment.