Sha256: c75e9056ba509a4490342612e803987258841b0e37a10117ff424c63c1c56dea

Contents?: true

Size: 608 Bytes

Versions: 17

Compression:

Stored size: 608 Bytes

Contents

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.
        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
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
github-linguist-4.5.4 lib/linguist/strategy/filename.rb
github-linguist-4.5.3 lib/linguist/strategy/filename.rb
github-linguist-4.5.2 lib/linguist/strategy/filename.rb
github-linguist-4.5.1 lib/linguist/strategy/filename.rb
github-linguist-4.4.3 lib/linguist/strategy/filename.rb
github-linguist-4.4.2 lib/linguist/strategy/filename.rb
github-linguist-4.4.1 lib/linguist/strategy/filename.rb
github-linguist-4.4.0 lib/linguist/strategy/filename.rb
github-linguist-4.3.1 lib/linguist/strategy/filename.rb
github-linguist-4.3.0 lib/linguist/strategy/filename.rb
github-linguist-4.2.7 lib/linguist/strategy/filename.rb
github-linguist-4.2.6 lib/linguist/strategy/filename.rb
github-linguist-4.2.5 lib/linguist/strategy/filename.rb
github-linguist-4.2.3 lib/linguist/strategy/filename.rb
github-linguist-4.2.2 lib/linguist/strategy/filename.rb
github-linguist-4.2.1 lib/linguist/strategy/filename.rb
github-linguist-4.2.0 lib/linguist/strategy/filename.rb