From 5a646384f6649474eb539d6c4c7734a244a98ec8 Mon Sep 17 00:00:00 2001 From: Paul Chaignon Date: Sun, 12 Jul 2015 20:56:51 +0200 Subject: [PATCH] FileBlob extends MemoryBlob --- lib/linguist/file_blob.rb | 45 ++------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 20d87bb0..98ef3825 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -1,10 +1,11 @@ require 'linguist/blob_helper' +require 'linguist/memory_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 + class FileBlob < MemoryBlob include BlobHelper # Public: Initialize a new FileBlob from a path @@ -18,20 +19,6 @@ module Linguist @path = base_path ? path.sub("#{base_path}/", '') : path end - # Public: Filename - # - # Examples - # - # FileBlob.new("/path/to/linguist/lib/linguist.rb").path - # # => "/path/to/linguist/lib/linguist.rb" - # - # FileBlob.new("/path/to/linguist/lib/linguist.rb", - # "/path/to/linguist").path - # # => "lib/linguist.rb" - # - # Returns a String - attr_reader :path - # Public: Read file permissions # # Returns a String like '100644' @@ -39,13 +26,6 @@ module Linguist File.stat(@fullpath).mode.to_s(8) end - # Public: File name - # - # Returns a String - def name - File.basename(@fullpath) - end - # Public: Read file contents. # # Returns a String. @@ -59,26 +39,5 @@ module Linguist def size File.size(@fullpath) end - - # Public: Get file extension. - # - # Returns a String. - def extension - extensions.last || "" - end - - # Public: Return an array of the file extensions - # - # >> Linguist::FileBlob.new("app/views/things/index.html.erb").extensions - # => [".html.erb", ".erb"] - # - # Returns an Array - def extensions - basename, *segments = name.downcase.split(".") - - segments.map.with_index do |segment, index| - "." + segments[index..-1].join(".") - end - end end end