Skip to content

Commit 3f5a96a

Browse files
committed
Merge pull request #2017 from github/revert-2014-revert-1976-path-for-fileblob
Cut 4.5.0 release
2 parents 188c736 + 840bdf9 commit 3f5a96a

File tree

6 files changed

+40
-20
lines changed

6 files changed

+40
-20
lines changed

lib/linguist/blob_helper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def disposition
9999
elsif name.nil?
100100
"attachment"
101101
else
102-
"attachment; filename=#{EscapeUtils.escape_url(File.basename(name))}"
102+
"attachment; filename=#{EscapeUtils.escape_url(name)}"
103103
end
104104
end
105105

@@ -233,7 +233,7 @@ def viewable?
233233
#
234234
# Return true or false
235235
def vendored?
236-
name =~ VendoredRegexp ? true : false
236+
path =~ VendoredRegexp ? true : false
237237
end
238238

239239
documentation_paths = YAML.load_file(File.expand_path("../documentation.yml", __FILE__))
@@ -248,7 +248,7 @@ def vendored?
248248
#
249249
# Return true or false
250250
def documentation?
251-
name =~ DocumentationRegexp ? true : false
251+
path =~ DocumentationRegexp ? true : false
252252
end
253253

254254
# Public: Get each line of data
@@ -316,7 +316,7 @@ def sloc
316316
#
317317
# Return true or false
318318
def generated?
319-
@_generated ||= Generated.generated?(name, lambda { data })
319+
@_generated ||= Generated.generated?(path, lambda { data })
320320
end
321321

322322
# Public: Detects the Language of the blob.

lib/linguist/file_blob.rb

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Linguist
44
# A FileBlob is a wrapper around a File object to make it quack
55
# like a Grit::Blob. It provides the basic interface: `name`,
6-
# `data`, and `size`.
6+
# `data`, `path` and `size`.
77
class FileBlob
88
include BlobHelper
99

@@ -14,43 +14,50 @@ class FileBlob
1414
#
1515
# Returns a FileBlob.
1616
def initialize(path, base_path = nil)
17-
@path = path
18-
@name = base_path ? path.sub("#{base_path}/", '') : path
17+
@fullpath = path
18+
@path = base_path ? path.sub("#{base_path}/", '') : path
1919
end
2020

2121
# Public: Filename
2222
#
2323
# Examples
2424
#
25-
# FileBlob.new("/path/to/linguist/lib/linguist.rb").name
25+
# FileBlob.new("/path/to/linguist/lib/linguist.rb").path
2626
# # => "/path/to/linguist/lib/linguist.rb"
2727
#
2828
# FileBlob.new("/path/to/linguist/lib/linguist.rb",
29-
# "/path/to/linguist").name
29+
# "/path/to/linguist").path
3030
# # => "lib/linguist.rb"
3131
#
3232
# Returns a String
33-
attr_reader :name
33+
attr_reader :path
3434

3535
# Public: Read file permissions
3636
#
3737
# Returns a String like '100644'
3838
def mode
39-
File.stat(@path).mode.to_s(8)
39+
File.stat(@fullpath).mode.to_s(8)
40+
end
41+
42+
# Public: File name
43+
#
44+
# Returns a String
45+
def name
46+
File.basename(@fullpath)
4047
end
4148

4249
# Public: Read file contents.
4350
#
4451
# Returns a String.
4552
def data
46-
File.read(@path)
53+
File.read(@fullpath)
4754
end
4855

4956
# Public: Get byte size
5057
#
5158
# Returns an Integer.
5259
def size
53-
File.size(@path)
60+
File.size(@fullpath)
5461
end
5562

5663
# Public: Get file extension.
@@ -67,7 +74,7 @@ def extension
6774
#
6875
# Returns an Array
6976
def extensions
70-
basename, *segments = File.basename(name).downcase.split(".")
77+
basename, *segments = name.downcase.split(".")
7178

7279
segments.map.with_index do |segment, index|
7380
"." + segments[index..-1].join(".")

lib/linguist/generated.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ def vcr_cassette?
281281
# Return true or false
282282
def compiled_cython_file?
283283
return false unless ['.c', '.cpp'].include? extname
284+
return false unless lines.count > 1
284285
return lines[0].include?("Generated by Cython")
285286
end
286287
end

lib/linguist/lazy_blob.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ class LazyBlob
1414

1515
attr_reader :repository
1616
attr_reader :oid
17-
attr_reader :name
17+
attr_reader :path
1818
attr_reader :mode
1919

20-
def initialize(repo, oid, name, mode = nil)
20+
alias :name :path
21+
22+
def initialize(repo, oid, path, mode = nil)
2123
@repository = repo
2224
@oid = oid
23-
@name = name
25+
@path = path
2426
@mode = mode
2527
end
2628

lib/linguist/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Linguist
2-
VERSION = "4.4.3"
2+
VERSION = "4.5.1"
33
end

test/test_blob.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ def test_generated
234234
assert sample_blob("Zephir/filenames/exception.zep.php").generated?
235235
assert !sample_blob("Zephir/Router.zep").generated?
236236

237-
238-
assert Linguist::Generated.generated?("node_modules/grunt/lib/grunt.js", nil)
237+
assert sample_blob("node_modules/grunt/lib/grunt.js").generated?
239238

240239
# Godep saved dependencies
241240
assert sample_blob("Godeps/Godeps.json").generated?
@@ -279,6 +278,8 @@ def test_vendored
279278
assert sample_blob("deps/http_parser/http_parser.c").vendored?
280279
assert sample_blob("deps/v8/src/v8.h").vendored?
281280

281+
assert sample_blob("tools/something/else.c").vendored?
282+
282283
# Chart.js
283284
assert sample_blob("some/vendored/path/Chart.js").vendored?
284285
assert !sample_blob("some/vendored/path/chart.js").vendored?
@@ -289,6 +290,9 @@ def test_vendored
289290
# Debian packaging
290291
assert sample_blob("debian/cron.d").vendored?
291292

293+
# Erlang
294+
assert sample_blob("rebar").vendored?
295+
292296
# Minified JavaScript and CSS
293297
assert sample_blob("foo.min.js").vendored?
294298
assert sample_blob("foo.min.css").vendored?
@@ -297,13 +301,19 @@ def test_vendored
297301
assert !sample_blob("foomin.css").vendored?
298302
assert !sample_blob("foo.min.txt").vendored?
299303

304+
#.osx
305+
assert sample_blob(".osx").vendored?
306+
300307
# Prototype
301308
assert !sample_blob("public/javascripts/application.js").vendored?
302309
assert sample_blob("public/javascripts/prototype.js").vendored?
303310
assert sample_blob("public/javascripts/effects.js").vendored?
304311
assert sample_blob("public/javascripts/controls.js").vendored?
305312
assert sample_blob("public/javascripts/dragdrop.js").vendored?
306313

314+
# Samples
315+
assert sample_blob("Samples/Ruby/foo.rb").vendored?
316+
307317
# jQuery
308318
assert sample_blob("jquery.js").vendored?
309319
assert sample_blob("public/javascripts/jquery.js").vendored?

0 commit comments

Comments
 (0)