Class: LanguageSniffer::FileBlob

Inherits:
Object
  • Object
show all
Includes:
BlobHelper
Defined in:
lib/language_sniffer/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`.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BlobHelper

#average_line_length, #disambiguate_extension_language, #extname, #first_line_language, #generated?, #generated_coffeescript?, #generated_net_docfile?, #guess_cls_language, #guess_gsp_language, #guess_h_language, #guess_language, #guess_m_language, #guess_pl_language, #guess_r_language, #guess_t_language, #guess_v_language, #language, #lines, #loc, #minified_javascript?, #pathname, #shebang_language, #shebang_script, #sloc, #visual_studio_project_file?, #xcode_project_file?

Constructor Details

#initialize(path, base_path = nil, data = 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
20
# File 'lib/language_sniffer/file_blob.rb', line 16

def initialize(path, base_path = nil, data=nil)
  @path = path
  @name = base_path ? path.sub("#{base_path}/", '') : path
  @data = data
end

Instance Attribute Details

#nameObject (readonly)

Public: Filename

Examples

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

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

Returns a String



34
35
36
# File 'lib/language_sniffer/file_blob.rb', line 34

def name
  @name
end

Instance Method Details

#dataObject

Public: Read file contents.

Returns a String.



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

def data
  @data ||= File.read(@path)
end