Class: Gollum::BlobEntry
- Inherits:
-
Object
- Object
- Gollum::BlobEntry
- Defined in:
- lib/gollum/blob_entry.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Gets the full path String for this blob.
-
#sha ⇒ Object
readonly
Gets the String SHA for this blob.
-
#size ⇒ Object
readonly
Gets the Fixnum size of this blob.
Class Method Summary collapse
-
.normalize_dir(dir) ⇒ Object
Normalizes a given directory name for searching through tree paths.
Instance Method Summary collapse
-
#blob(repo) ⇒ Object
Gets a Grit::Blob instance for this blob.
-
#dir ⇒ Object
Gets the normalized directory path String for this blob.
-
#initialize(sha, path, size = nil) ⇒ BlobEntry
constructor
A new instance of BlobEntry.
- #inspect ⇒ Object
-
#name ⇒ Object
Gets the file base name String for this blob.
-
#page(wiki, commit) ⇒ Object
Gets a Page instance for this blob.
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
#path ⇒ Object (readonly)
Gets the full path String for this blob.
7 8 9 |
# File 'lib/gollum/blob_entry.rb', line 7 def path @path end |
#sha ⇒ Object (readonly)
Gets the String SHA for this blob.
4 5 6 |
# File 'lib/gollum/blob_entry.rb', line 4 def sha @sha end |
#size ⇒ Object (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.(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 |
#dir ⇒ Object
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 |
#inspect ⇒ Object
51 52 53 |
# File 'lib/gollum/blob_entry.rb', line 51 def inspect %(#<Gollum::BlobEntry #{@sha} #{@path}>) end |
#name ⇒ Object
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 |