aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2012-08-20 11:20:37 -0500
committerJoshua Peek <josh@joshpeek.com>2012-08-20 11:20:37 -0500
commitf8df871d85057633714002d9650408dbebd7834e (patch)
tree5941d75c241dddac9435d2070a94bb494db5e4b4
parent620150d1880347fabda218b6edaf6611725cfe9a (diff)
Only double check binary mime type when lazy loading blob
-rw-r--r--lib/linguist/blob_helper.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb
index f8a4cfb..09d1bf3 100644
--- a/lib/linguist/blob_helper.rb
+++ b/lib/linguist/blob_helper.rb
@@ -83,7 +83,7 @@ module Linguist
@detect_encoding ||= CharlockHolmes::EncodingDetector.new.detect(data) if data
end
- # Public: Is the blob binary according to its mime type
+ # Internal: Is the blob binary according to its mime type
#
# Return true or false
def binary_mime_type?
@@ -260,8 +260,14 @@ module Linguist
# Returns a Language or nil if none is detected
def language
return @language if defined? @language
- data_loader = lambda { binary_mime_type? ? "" : data }
- @language = Language.detect(name.to_s, data_loader, mode)
+
+ if defined?(@data) && @data.is_a?(String)
+ data = @data
+ else
+ data = lambda { binary_mime_type? ? "" : self.data }
+ end
+
+ @language = Language.detect(name.to_s, data, mode)
end
# Internal: Get the lexer of the blob.