This commit is contained in:
Brandon Keepers
2014-11-28 12:27:48 -06:00
parent 9020d7c044
commit c05717d15c

View File

@@ -1,10 +1,22 @@
module Linguist
# Check if there's a shebang line and use that as authoritative
class Shebang
def self.call(blob, _)
# Public: Use shebang to detect language of the blob.
#
# blob - An object that quacks like a blob.
#
# Examples
#
# Shebang.call(FileBlob.new("path/to/file"))
#
# Returns an Array with one Language if the blob has a shebang with a valid
# interpreter, or empty if there is no shebang.
def self.call(blob, _ = nil)
Language.find_by_interpreter interpreter(blob.data)
end
# Public: Get the interpreter from the shebang
#
# Returns a String or nil
def self.interpreter(data)
lines = data.lines
return unless match = /^#! ?(.*)$/.match(lines.first)