diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index 07e1ee52..c368b4d0 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -99,7 +99,7 @@ module Linguist elsif name.nil? "attachment" else - "attachment; filename=#{EscapeUtils.escape_url(name)}" + "attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}" end end @@ -233,7 +233,7 @@ module Linguist # # Return true or false def vendored? - path =~ VendoredRegexp ? true : false + name =~ VendoredRegexp ? true : false end # Public: Get each line of data @@ -301,7 +301,7 @@ module Linguist # # Return true or false def generated? - @_generated ||= Generated.generated?(path, lambda { data }) + @_generated ||= Generated.generated?(name, lambda { data }) end # Public: Detects the Language of the blob. diff --git a/lib/linguist/file_blob.rb b/lib/linguist/file_blob.rb index 2ca74c2d..04441935 100644 --- a/lib/linguist/file_blob.rb +++ b/lib/linguist/file_blob.rb @@ -3,7 +3,7 @@ require 'linguist/blob_helper' 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`. + # `data`, and `size`. class FileBlob include BlobHelper @@ -14,50 +14,43 @@ module Linguist # # Returns a FileBlob. def initialize(path, base_path = nil) - @fullpath = path - @path = base_path ? path.sub("#{base_path}/", '') : path + @path = path + @name = base_path ? path.sub("#{base_path}/", '') : path end # Public: Filename # # Examples # - # FileBlob.new("/path/to/linguist/lib/linguist.rb").path + # 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").path + # "/path/to/linguist").name # # => "lib/linguist.rb" # # Returns a String - attr_reader :path + attr_reader :name # Public: Read file permissions # # Returns a String like '100644' def mode - File.stat(@fullpath).mode.to_s(8) - end - - # Public: File name - # - # Returns a String - def name - File.basename(@fullpath) + File.stat(@path).mode.to_s(8) end # Public: Read file contents. # # Returns a String. def data - File.read(@fullpath) + File.read(@path) end # Public: Get byte size # # Returns an Integer. def size - File.size(@fullpath) + File.size(@path) end # Public: Get file extension. @@ -74,7 +67,7 @@ module Linguist # # Returns an Array def extensions - basename, *segments = name.split(".") + basename, *segments = File.basename(name).split(".") segments.map.with_index do |segment, index| "." + segments[index..-1].join(".") diff --git a/lib/linguist/lazy_blob.rb b/lib/linguist/lazy_blob.rb index ab6c4bee..9691bca5 100644 --- a/lib/linguist/lazy_blob.rb +++ b/lib/linguist/lazy_blob.rb @@ -14,15 +14,13 @@ module Linguist attr_reader :repository attr_reader :oid - attr_reader :path + attr_reader :name attr_reader :mode - alias :name :path - - def initialize(repo, oid, path, mode = nil) + def initialize(repo, oid, name, mode = nil) @repository = repo @oid = oid - @path = path + @name = name @mode = mode end diff --git a/test/test_blob.rb b/test/test_blob.rb index 4c4f7978..372ff13f 100644 --- a/test/test_blob.rb +++ b/test/test_blob.rb @@ -251,7 +251,8 @@ class TestBlob < Minitest::Test assert sample_blob("Zephir/filenames/exception.zep.php").generated? assert !sample_blob("Zephir/Router.zep").generated? - assert sample_blob("node_modules/grunt/lib/grunt.js").generated? + + assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil) # Godep saved dependencies assert sample_blob("Godeps/Godeps.json").generated? @@ -291,8 +292,6 @@ class TestBlob < Minitest::Test assert sample_blob("deps/http_parser/http_parser.c").vendored? assert sample_blob("deps/v8/src/v8.h").vendored? - assert sample_blob("tools/something/else.c").vendored? - # Chart.js assert sample_blob("some/vendored/path/Chart.js").vendored? assert !sample_blob("some/vendored/path/chart.js").vendored? @@ -303,9 +302,6 @@ class TestBlob < Minitest::Test # Debian packaging assert sample_blob("debian/cron.d").vendored? - # Erlang - assert sample_blob("rebar").vendored? - # Minified JavaScript and CSS assert sample_blob("foo.min.js").vendored? assert sample_blob("foo.min.css").vendored? @@ -314,9 +310,6 @@ class TestBlob < Minitest::Test assert !sample_blob("foomin.css").vendored? assert !sample_blob("foo.min.txt").vendored? - #.osx - assert sample_blob(".osx").vendored? - # Prototype assert !sample_blob("public/javascripts/application.js").vendored? assert sample_blob("public/javascripts/prototype.js").vendored? @@ -324,9 +317,6 @@ class TestBlob < Minitest::Test assert sample_blob("public/javascripts/controls.js").vendored? assert sample_blob("public/javascripts/dragdrop.js").vendored? - # Samples - assert sample_blob("Samples/Ruby/foo.rb").vendored? - # jQuery assert sample_blob("jquery.js").vendored? assert sample_blob("public/javascripts/jquery.js").vendored?