Files
gollum/lib/gollum/file.rb
T
Tom Preston-Werner 2e328e6a83 implement File finding
2010-04-11 13:08:16 -06:00

37 lines
781 B
Ruby

module Gollum
class File
attr_accessor :wiki, :blob
# Initialize a file.
#
# wiki - The Gollum::Wiki in question.
#
# Returns a newly initialized Gollum::File.
def initialize(wiki)
self.wiki = wiki
end
# The raw contents of the page.
#
# Returns the String data.
def raw_data
self.blob.data rescue nil
end
# Find a file in the given Gollum repo.
#
# name - The full String path.
# version - The String version ID to find.
#
# Returns a Gollum::File or nil if the file could not be found.
def find(name, version)
commit = self.wiki.repo.commit(version)
if blob = commit.tree / name
self.blob = blob
self
else
nil
end
end
end
end