mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Doc FileBlob
This commit is contained in:
@@ -1,20 +1,47 @@
|
|||||||
require 'linguist/blob_helper'
|
require 'linguist/blob_helper'
|
||||||
|
|
||||||
module Linguist
|
module Linguist
|
||||||
|
# A FileBlob is a wrapper around an File object to make it quack
|
||||||
|
# like a Grit::Blob. It provides the basic interface: `name`,
|
||||||
|
# `data`, and `size`.
|
||||||
class FileBlob
|
class FileBlob
|
||||||
include BlobHelper
|
include BlobHelper
|
||||||
|
|
||||||
|
# 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.
|
||||||
def initialize(path, base_path = nil)
|
def initialize(path, base_path = nil)
|
||||||
@path = path
|
@path = path
|
||||||
@name = base_path ? path.sub("#{base_path}/", '') : path
|
@name = base_path ? path.sub("#{base_path}/", '') : path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Filename
|
||||||
|
#
|
||||||
|
# Examples
|
||||||
|
#
|
||||||
|
# FileBlob.new("/path/to/linguist/lib/linguist.rb").name
|
||||||
|
# # => "/path/to/linguist/lib/linguist.rb"
|
||||||
|
#
|
||||||
|
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
|
||||||
|
# "/path/to/linguist").name
|
||||||
|
# # => "lib/linguist.rb"
|
||||||
|
#
|
||||||
|
# Returns a String
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
|
# Public: Read file contents.
|
||||||
|
#
|
||||||
|
# Returns a String.
|
||||||
def data
|
def data
|
||||||
File.read(@path)
|
File.read(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Public: Get byte size
|
||||||
|
#
|
||||||
|
# Returns an Integer.
|
||||||
def size
|
def size
|
||||||
File.size(@path)
|
File.size(@path)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user