Class: Linguist::FileBlob

Inherits:
Blob
  • Object
show all
Includes:
BlobHelper
Defined in:
lib/linguist/file_blob.rb

Overview

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`.

Constant Summary

Constants included from BlobHelper

BlobHelper::DETECTABLE_TYPES, BlobHelper::DocumentationRegexp, BlobHelper::MEGABYTE, BlobHelper::VendoredRegexp

Instance Attribute Summary

Attributes inherited from Blob

#path

Instance Method Summary collapse

Methods included from BlobHelper

#_mime_type, #binary?, #binary_mime_type?, #content_type, #csv?, #detect_encoding, #disposition, #documentation?, #empty?, #encoding, #extname, #generated?, #high_ratio_of_long_lines?, #image?, #include_in_language_stats?, #language, #large?, #likely_binary?, #lines, #loc, #mime_type, #pdf?, #ruby_encoding, #safe_to_colorize?, #sloc, #solid?, #text?, #tm_scope, #vendored?, #viewable?

Methods inherited from Blob

#extension, #extensions, #name

Constructor Details

#initialize(path, base_path = nil) ⇒ FileBlob

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.



17
18
19
20
# 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

Instance Method Details

#dataObject

Public: Read file contents.

Returns a String.



32
33
34
# File 'lib/linguist/file_blob.rb', line 32

def data
  File.read(@fullpath)
end

#modeObject

Public: Read file permissions

Returns a String like ‘100644’



25
26
27
# File 'lib/linguist/file_blob.rb', line 25

def mode
  File.stat(@fullpath).mode.to_s(8)
end

#sizeObject

Public: Get byte size

Returns an Integer.



39
40
41
# File 'lib/linguist/file_blob.rb', line 39

def size
  File.size(@fullpath)
end