mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
21 lines
605 B
Ruby
21 lines
605 B
Ruby
module Linguist
|
|
module Strategy
|
|
# Detects language based on filename and/or extension
|
|
class Filename
|
|
def self.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
|
|
|
|
Language.find_by_filename(name)
|
|
end
|
|
end
|
|
end
|
|
end
|