Extract filename strategy

This commit is contained in:
Brandon Keepers
2014-11-02 22:15:52 -05:00
parent f2cd75332c
commit 8d7b4f81b4
2 changed files with 23 additions and 12 deletions

View File

@@ -0,0 +1,20 @@
module Linguist
module Strategy
class Filename
def call(blob)
name = blob.name.to_s
# A bit of an elegant hack. If the file is executable but extensionless,
# append a "magic" extension so it can be classified with other
# languages that have shebang scripts.
extension = FileBlob.new(name).extension
if extension.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
name += ".script!"
end
# First try to find languages that match based on filename.
possible_languages = Language.find_by_filename(name)
end
end
end
end