Class: Linguist::FileBlob
- Inherits:
-
Object
- Object
- Linguist::FileBlob
- 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`, and `size`.
Constant Summary
Constants included from BlobHelper
BlobHelper::MEGABYTE, BlobHelper::VendoredRegexp
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Public: Filename.
Instance Method Summary collapse
-
#data ⇒ Object
Public: Read file contents.
-
#initialize(path, base_path = nil) ⇒ FileBlob
constructor
Public: Initialize a new FileBlob from a path.
-
#mode ⇒ Object
Public: Read file permissions.
-
#size ⇒ Object
Public: Get byte size.
Methods included from BlobHelper
#_mime_type, #binary?, #binary_mime_type?, #colorize, #colorize_without_wrapper, #content_type, #detect_encoding, #disposition, #encoding, #extname, #generated?, #high_ratio_of_long_lines?, #image?, #indexable?, #language, #large?, #lexer, #likely_binary?, #line_split_character, #lines, #loc, #mac_format?, #mime_type, #pdf?, #safe_to_colorize?, #sloc, #solid?, #text?, #vendored?, #viewable?
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.
16 17 18 19 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
33 34 35 |
# File 'lib/linguist/file_blob.rb', line 33 def name @name end |
Instance Method Details
#data ⇒ Object
Public: Read file contents.
Returns a String.
45 46 47 |
# File 'lib/linguist/file_blob.rb', line 45 def data File.read(@path) end |
#mode ⇒ Object
Public: Read file permissions
Returns a String like ‘100644’
38 39 40 |
# File 'lib/linguist/file_blob.rb', line 38 def mode File.stat(@path).mode.to_s(8) end |
#size ⇒ Object
Public: Get byte size
Returns an Integer.
52 53 54 |
# File 'lib/linguist/file_blob.rb', line 52 def size File.size(@path) end |