Class: Linguist::Strategy::Filename

Inherits:
Object
  • Object
show all
Defined in:
lib/linguist/strategy/filename.rb

Overview

Detects language based on filename and/or extension

Class Method Summary collapse

Class Method Details

.call(blob, _) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/linguist/strategy/filename.rb', line 5

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.
  extensions = FileBlob.new(name).extensions
  if extensions.empty? && blob.mode && (blob.mode.to_i(8) & 05) == 05
    name += ".script!"
  end

  Language.find_by_filename(name)
end