Class: 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`, `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
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.
- #symlink? ⇒ Boolean
Methods included from BlobHelper
#_mime_type, #binary?, #binary_mime_type?, #content_type, #csv?, #detect_encoding, #disposition, #documentation?, #empty?, #encoded_newlines_re, #encoding, #extname, #first_lines, #generated?, #high_ratio_of_long_lines?, #image?, #include_in_language_stats?, #language, #large?, #last_lines, #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
#data ⇒ Object
Public: Read file contents.
Returns a String.
37 38 39 |
# File 'lib/linguist/file_blob.rb', line 37 def data @data ||= File.read(@fullpath, :encoding => "ASCII-8BIT") end |
#mode ⇒ Object
Public: Read file permissions
Returns a String like ‘100644’
25 26 27 |
# File 'lib/linguist/file_blob.rb', line 25 def mode @mode ||= File.stat(@fullpath).mode.to_s(8) end |
#size ⇒ Object
Public: Get byte size
Returns an Integer.
44 45 46 |
# File 'lib/linguist/file_blob.rb', line 44 def size @size ||= File.size(@fullpath) end |
#symlink? ⇒ Boolean
29 30 31 32 |
# File 'lib/linguist/file_blob.rb', line 29 def symlink? return @symlink if defined? @symlink @symlink = (File.symlink?(@fullpath) rescue false) end |