Class: Gollum::BlobEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/gollum/blob_entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sha, path, size = nil) ⇒ BlobEntry

Returns a new instance of BlobEntry.



12
13
14
15
16
17
# File 'lib/gollum/blob_entry.rb', line 12

def initialize(sha, path, size = nil)
  @sha  = sha
  @path = path
  @size = size
  @dir  = @name = @blob = nil
end

Instance Attribute Details

#pathObject (readonly)

Gets the full path String for this blob.



7
8
9
# File 'lib/gollum/blob_entry.rb', line 7

def path
  @path
end

#shaObject (readonly)

Gets the String SHA for this blob.



4
5
6
# File 'lib/gollum/blob_entry.rb', line 4

def sha
  @sha
end

#sizeObject (readonly)

Gets the Fixnum size of this blob.



10
11
12
# File 'lib/gollum/blob_entry.rb', line 10

def size
  @size
end

Class Method Details

.normalize_dir(dir) ⇒ Object

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.



69
70
71
72
73
74
75
76
# File 'lib/gollum/blob_entry.rb', line 69

def self.normalize_dir(dir)
  return '' if dir =~ /^.:\/$/
  if dir
    dir = ::File.expand_path(dir, '/')
    dir = '' if dir == '/'
  end
  dir
end

Instance Method Details

#blob(repo) ⇒ Object

Gets a Grit::Blob instance for this blob.

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

Returns an unbaked Grit::Blob instance.



34
35
36
37
# File 'lib/gollum/blob_entry.rb', line 34

def blob(repo)
  @blob ||= Grit::Blob.create(repo,
    :id => @sha, :name => name, :size => @size)
end

#dirObject

Gets the normalized directory path String for this blob.



20
21
22
# File 'lib/gollum/blob_entry.rb', line 20

def dir
  @dir ||= self.class.normalize_dir(::File.dirname(@path))
end

#inspectObject



51
52
53
# File 'lib/gollum/blob_entry.rb', line 51

def inspect
  %(#<Gollum::BlobEntry #{@sha} #{@path}>)
end

#nameObject

Gets the file base name String for this blob.



25
26
27
# File 'lib/gollum/blob_entry.rb', line 25

def name
  @name ||= ::File.basename(@path)
end

#page(wiki, commit) ⇒ Object

Gets a Page instance for this blob.

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

Returns a Gollum::Page instance.



44
45
46
47
48
49
# File 'lib/gollum/blob_entry.rb', line 44

def page(wiki, commit)
  blob = self.blob(wiki.repo)
  page = wiki.page_class.new(wiki).populate(blob, self.dir)
  page.version = commit
  page
end