From 67f30692e7751f450e21874e6037d9ff5397d774 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 14 Jun 2011 00:10:50 -0500 Subject: [PATCH] Doc FileBlob --- lib/linguist/file_blob.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 744685a5..7c0359e1 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -1,20 +1,47 @@ require 'linguist/blob_helper' 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 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) @path = path @name = base_path ? path.sub("#{base_path}/", '') : path 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 + # Public: Read file contents. + # + # Returns a String. def data File.read(@path) end + # Public: Get byte size + # + # Returns an Integer. def size File.size(@path) end