Parent

Included Modules

Linguist::FileBlob

A FileBlob is a wrapper around a File object to make it quack like a Grit::Blob. It provides the basic interface: `name`, `data`, and `size`.

Attributes

name[R]

Public: Filename

Examples

FileBlob.new("/path/to/linguist/lib/linguist.rb").name
# =>  "/path/to/linguist/lib/linguist.rb"

FileBlob.new("/path/to/linguist/lib/linguist.rb",
             "/path/to/linguist").name
# =>  "lib/linguist.rb"

Returns a String

Public Class Methods

new(path, base_path = nil) click to toggle source

Public: Initialize a new FileBlob from a path

path - A path String that exists on the file system. base_path - Optional base to relativize the path

Returns a FileBlob.

# File lib/linguist/file_blob.rb, line 16
def initialize(path, base_path = nil)
  @path = path
  @name = base_path ? path.sub("#{base_path}/", '') : path
end

Public Instance Methods

data() click to toggle source

Public: Read file contents.

Returns a String.

# File lib/linguist/file_blob.rb, line 45
def data
  File.read(@path)
end
extension() click to toggle source

Public: Get file extension.

Returns a String.

# File lib/linguist/file_blob.rb, line 59
def extension
  # File.extname returns nil if the filename is an extension.
  extension = File.extname(name)
  basename = File.basename(name)
  # Checks if the filename is an extension.
  if extension.empty? && basename[0] == "."
    basename
  else
    extension
  end
end
mode() click to toggle source

Public: Read file permissions

Returns a String like ‘100644’

# File lib/linguist/file_blob.rb, line 38
def mode
  File.stat(@path).mode.to_s(8)
end
size() click to toggle source

Public: Get byte size

Returns an Integer.

# File lib/linguist/file_blob.rb, line 52
def size
  File.size(@path)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.