class 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`, `path` and `size`.
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 17 def initialize(path, base_path = nil) @fullpath = path @path = 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 32 def data @data ||= File.read(@fullpath) end
mode()
click to toggle source
Public: Read file permissions
Returns a String like '100644'
# File lib/linguist/file_blob.rb, line 25 def mode @mode ||= File.stat(@fullpath).mode.to_s(8) end
size()
click to toggle source
Public: Get byte size
Returns an Integer.
# File lib/linguist/file_blob.rb, line 39 def size @size ||= File.size(@fullpath) end