mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-12-08 12:28:47 +00:00
Extract empty blob strategy
This commit is contained in:
@@ -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
|
||||||
|
|||||||
10
lib/linguist/strategy/empty_blob.rb
Normal file
10
lib/linguist/strategy/empty_blob.rb
Normal 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
|
||||||
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user