Sha256: 852aff84cd28615708e0ee214bb55c411d49334cc9bb369f8762bdef8f1db10a

Contents?: true

Size: 1.96 KB

Versions: 36

Compression:

Stored size: 1.96 KB

Contents

module Gollum
  class BlobEntry
    # Gets the String SHA for this blob.
    attr_reader :sha

    # Gets the full path String for this blob.
    attr_reader :path

    # Gets the Fixnum size of this blob.
    attr_reader :size

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

    # Gets the normalized directory path String for this blob.
    def dir
      @dir ||= self.class.normalize_dir(::File.dirname(@path))
    end

    # Gets the file base name String for this blob.
    def name
      @name ||= ::File.basename(@path)
    end

    # Gets a Grit::Blob instance for this blob.
    #
    # repo - Grit::Repo instance for the Grit::Blob.
    #
    # Returns an unbaked Grit::Blob instance.
    def blob(repo)
      @blob ||= Grit::Blob.create(repo,
        :id => @sha, :name => name, :size => @size)
    end

    # Gets a Page instance for this blob.
    #
    # wiki - Gollum::Wiki instance for the Gollum::Page
    #
    # Returns a Gollum::Page instance.
    def page(wiki, commit)
      blob = self.blob(wiki.repo)
      page = wiki.page_class.new(wiki).populate(blob, self.dir)
      page.version = commit
      page
    end

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

    # 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.
    def self.normalize_dir(dir)
      return '' if dir =~ /^.:\/$/
      if dir
        dir = ::File.expand_path(dir, '/')
        dir = '' if dir == '/'
      end
      dir
    end
  end
end

Version data entries

36 entries across 36 versions & 6 rubygems

Version Path
gollum-2.0.0 lib/gollum/blob_entry.rb
gollum-1.4.3 lib/gollum/blob_entry.rb
gollum-1.4.2 lib/gollum/blob_entry.rb
read-only-gollum-1.4.0 lib/gollum/blob_entry.rb
gollum-bibanon-1.4.4 lib/gollum/blob_entry.rb
gollum-bibanon-1.4.3 lib/gollum/blob_entry.rb
rtfmd-0.10301.20 lib/gollum/blob_entry.rb
gollum-bibanon-1.4.2 lib/gollum/blob_entry.rb
gollum-bibanon-1.4.1 lib/gollum/blob_entry.rb
gollum-bibanon-1.3.2 lib/gollum/blob_entry.rb
gollum-bibanon-1.4.0 lib/gollum/blob_entry.rb
gollum-bibanon-1.3.1 lib/gollum/blob_entry.rb
rtfmd-0.10301.19 lib/gollum/blob_entry.rb
rtfmd-0.10301.18 lib/gollum/blob_entry.rb
rtfmd-0.10301.17 lib/gollum/blob_entry.rb
RTFMd-0.10301.17 lib/gollum/blob_entry.rb
RTFMd-0.10301.16 lib/gollum/blob_entry.rb
RTFMd-0.10301.15 lib/gollum/blob_entry.rb
RTFMd-0.10301.14 lib/gollum/blob_entry.rb
RTFMd-0.10301.13 lib/gollum/blob_entry.rb