Extract empty blob strategy

This commit is contained in:
Brandon Keepers
2014-11-03 08:21:46 -05:00
parent fd32938cd8
commit 815337299a
3 changed files with 14 additions and 3 deletions

View File

@@ -93,13 +93,13 @@ module Linguist
end end
require 'linguist/strategy/filename' require 'linguist/strategy/filename'
require 'linguist/strategy/empty_blob'
require 'linguist/strategy/shebang' require 'linguist/strategy/shebang'
require 'linguist/strategy/classifier' require 'linguist/strategy/classifier'
STRATEGIES = [ STRATEGIES = [
Linguist::Strategy::Filename, Linguist::Strategy::Filename,
# Don't bother with binary contents or an empty file Linguist::Strategy::EmptyBlob,
lambda {|blob, langauges| [] if blob.data.nil? || blob.data == "" },
# Check if there's a shebang line and use that as authoritative
Linguist::Strategy::Shebang, Linguist::Strategy::Shebang,
Linguist::Heuristics, Linguist::Heuristics,
Linguist::Strategy::Classifier Linguist::Strategy::Classifier

View File

@@ -0,0 +1,10 @@
module Linguist
module Strategy
class EmptyBlob
def self.call(blob, langauges)
# Don't bother with binary contents or an empty file
[] if blob.data.nil? || blob.data == ""
end
end
end
end

View File

@@ -1,5 +1,6 @@
module Linguist module Linguist
module Strategy module Strategy
# Check if there's a shebang line and use that as authoritative
class Shebang class Shebang
def self.call(blob, _) def self.call(blob, _)
Language.find_by_shebang(blob.data) Language.find_by_shebang(blob.data)