From 815337299a9cfc988460ff02924b303bd3d89bd9 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 3 Nov 2014 08:21:46 -0500 Subject: [PATCH] Extract empty blob strategy --- lib/linguist/language.rb | 6 +++--- lib/linguist/strategy/empty_blob.rb | 10 ++++++++++ lib/linguist/strategy/shebang.rb | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 lib/linguist/strategy/empty_blob.rb diff --git a/lib/linguist/language.rb b/lib/linguist/language.rb index 58881125..17b7ddad 100644 --- a/lib/linguist/language.rb +++ b/lib/linguist/language.rb @@ -93,13 +93,13 @@ module Linguist end require 'linguist/strategy/filename' + require 'linguist/strategy/empty_blob' require 'linguist/strategy/shebang' require 'linguist/strategy/classifier' + STRATEGIES = [ Linguist::Strategy::Filename, - # Don't bother with binary contents or an empty file - lambda {|blob, langauges| [] if blob.data.nil? || blob.data == "" }, - # Check if there's a shebang line and use that as authoritative + Linguist::Strategy::EmptyBlob, Linguist::Strategy::Shebang, Linguist::Heuristics, Linguist::Strategy::Classifier diff --git a/lib/linguist/strategy/empty_blob.rb b/lib/linguist/strategy/empty_blob.rb new file mode 100644 index 00000000..cc30477d --- /dev/null +++ b/lib/linguist/strategy/empty_blob.rb @@ -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 diff --git a/lib/linguist/strategy/shebang.rb b/lib/linguist/strategy/shebang.rb index 244e4c85..dd5bc38b 100644 --- a/lib/linguist/strategy/shebang.rb +++ b/lib/linguist/strategy/shebang.rb @@ -1,5 +1,6 @@ module Linguist module Strategy + # Check if there's a shebang line and use that as authoritative class Shebang def self.call(blob, _) Language.find_by_shebang(blob.data)