Sha256: e08371b0065b1b8a5841478d9dbce4900f429a3493ac791dca309141a8332c94
Contents?: true
Size: 999 Bytes
Versions: 41
Compression:
Stored size: 999 Bytes
Contents
require 'linguist/blob_helper' require 'linguist/blob' module Linguist # 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`. class FileBlob < Blob 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) @fullpath = path @path = base_path ? path.sub("#{base_path}/", '') : path end # Public: Read file permissions # # Returns a String like '100644' def mode File.stat(@fullpath).mode.to_s(8) end # Public: Read file contents. # # Returns a String. def data File.read(@fullpath) end # Public: Get byte size # # Returns an Integer. def size File.size(@fullpath) end end end
Version data entries
41 entries across 41 versions & 1 rubygems