Class: Gollum::BlobEntry
- Inherits:
-
Object
- Object
- Gollum::BlobEntry
- Defined in:
- lib/gollum-lib/blob_entry.rb
Instance Attribute Summary collapse
-
#mode ⇒ Object
readonly
Gets the Fixnum mode of this blob.
-
#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 Gollum::Git::Blob instance for this blob.
-
#dir ⇒ Object
Gets the normalized directory path String for this blob.
-
#file(wiki, commit) ⇒ Object
Gets a File instance for this blob.
-
#initialize(sha, path, size = nil, mode = 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, mode = nil) ⇒ BlobEntry
Returns a new instance of BlobEntry.
16 17 18 19 20 21 22 |
# File 'lib/gollum-lib/blob_entry.rb', line 16 def initialize(sha, path, size = nil, mode = nil) @sha = sha @path = path @size = size @mode = mode @dir = @name = @blob = nil end |
Instance Attribute Details
#mode ⇒ Object (readonly)
Gets the Fixnum mode of this blob.
14 15 16 |
# File 'lib/gollum-lib/blob_entry.rb', line 14 def mode @mode end |
#path ⇒ Object (readonly)
Gets the full path String for this blob.
8 9 10 |
# File 'lib/gollum-lib/blob_entry.rb', line 8 def path @path end |
#sha ⇒ Object (readonly)
Gets the String SHA for this blob.
5 6 7 |
# File 'lib/gollum-lib/blob_entry.rb', line 5 def sha @sha end |
#size ⇒ Object (readonly)
Gets the Fixnum size of this blob.
11 12 13 |
# File 'lib/gollum-lib/blob_entry.rb', line 11 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gollum-lib/blob_entry.rb', line 80 def self.normalize_dir(dir) return unless dir dir = dir.dup # Remove '.' and '..' path segments dir.gsub!(%r{(\A|/)\.{1,2}(/|\z)}, '/') # Remove repeated slashes dir.gsub!(%r{//+}, '/') # Remove Windows drive letters, trailing slashes, and keep one leading slash dir.sub!(%r{\A([a-z]:)?/*(.*?)/*\z}i, '/\2') # Return empty string for paths that point to the toplevel return '' if dir == '/' dir end |
Instance Method Details
#blob(repo) ⇒ Object
Gets a Gollum::Git::Blob instance for this blob.
repo - Gollum::Git::Repo instance for the Gollum::Git::Blob.
Returns an unbaked Gollum::Git::Blob instance.
39 40 41 42 |
# File 'lib/gollum-lib/blob_entry.rb', line 39 def blob(repo) @blob ||= Gollum::Git::Blob.create(repo, :id => @sha, :name => name, :size => @size, :mode => @mode) end |
#dir ⇒ Object
Gets the normalized directory path String for this blob.
25 26 27 |
# File 'lib/gollum-lib/blob_entry.rb', line 25 def dir @dir ||= self.class.normalize_dir(::File.dirname(@path)) end |
#file(wiki, commit) ⇒ Object
Gets a File instance for this blob.
wiki - Gollum::Wiki instance for the Gollum::File
Returns a Gollum::File instance.
58 59 60 |
# File 'lib/gollum-lib/blob_entry.rb', line 58 def file(wiki, commit) ::Gollum::File.new(wiki, self.blob(wiki.repo), self.dir, commit) end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/gollum-lib/blob_entry.rb', line 62 def inspect %(#<Gollum::BlobEntry #{@sha} #{@path}>) end |
#name ⇒ Object
Gets the file base name String for this blob.
30 31 32 |
# File 'lib/gollum-lib/blob_entry.rb', line 30 def name @name ||= ::File.basename(@path) end |