class Gollum::BlobEntry

Attributes

mode[R]

Gets the Fixnum mode of this blob.

path[R]

Gets the full path String for this blob.

sha[R]

Gets the String SHA for this blob.

size[R]

Gets the Fixnum size of this blob.

Public Class Methods

new(sha, path, size = nil, mode = nil) click to toggle source
# File lib/gollum-lib/blob_entry.rb, line 15
def initialize(sha, path, size = nil, mode = nil)
  @sha  = sha
  @path = path
  @size = size
  @mode = mode
  @dir  = @name = @blob = nil
end
normalize_dir(dir) click to toggle source

Normalizes a given directory name for searching through tree paths. Ensures that a directory begins with a slash, or

normalize_dir("")      # => ""
normalize_dir(".")     # => ""
normalize_dir("foo")   # => "/foo"
normalize_dir("/foo/") # => "/foo"
normalize_dir("/")     # => ""
normalize_dir("c:/")   # => ""

dir - String directory name.

Returns a normalized String directory name, or nil if no directory is given.

# File lib/gollum-lib/blob_entry.rb, line 85
def self.normalize_dir(dir)
  return '' if dir =~ /^.:\/$/
  if dir
    dir = ::File.expand_path(dir, '/')
    dir = '' if dir == '/'
  end
  dir
end

Public Instance Methods

blob(repo) click to toggle source

Gets a Grit::Blob instance for this blob.

repo - Grit::Repo instance for the Grit::Blob.

Returns an unbaked Grit::Blob instance.

# File lib/gollum-lib/blob_entry.rb, line 38
def blob(repo)
  @blob ||= Grit::Blob.create(repo,
    :id => @sha, :name => name, :size => @size, :mode => @mode)
end
dir() click to toggle source

Gets the normalized directory path String for this blob.

# File lib/gollum-lib/blob_entry.rb, line 24
def dir
  @dir ||= self.class.normalize_dir(::File.dirname(@path))
end
file(wiki, commit) click to toggle source

Gets a File instance for this blob.

wiki - Gollum::Wiki instance for the Gollum::File

Returns a Gollum::File instance.

# File lib/gollum-lib/blob_entry.rb, line 60
def file(wiki, commit)
  blob = self.blob(wiki.repo)
  file = wiki.file_class.new(wiki).populate(blob, self.dir)
  file.version = commit
  file
end
inspect() click to toggle source
# File lib/gollum-lib/blob_entry.rb, line 67
def inspect
  %Q(#<Gollum::BlobEntry #{@sha} #{@path}>)
end
name() click to toggle source

Gets the file base name String for this blob.

# File lib/gollum-lib/blob_entry.rb, line 29
def name
  @name ||= ::File.basename(@path)
end
page(wiki, commit) click to toggle source

Gets a Page instance for this blob.

wiki - Gollum::Wiki instance for the Gollum::Page

Returns a Gollum::Page instance.

# File lib/gollum-lib/blob_entry.rb, line 48
def page(wiki, commit)
  blob = self.blob(wiki.repo)
  page = wiki.page_class.new(wiki).populate(blob, self.dir)
  page.version = commit
  page
end