diff --git a/lib/linguist/blob_helper.rb b/lib/linguist/blob_helper.rb index bec40bc8..bcc79902 100644 --- a/lib/linguist/blob_helper.rb +++ b/lib/linguist/blob_helper.rb @@ -256,7 +256,7 @@ module Linguist language # See if there is a Language for the extension - elsif language = Language.find_by_filename(pathname.to_s) + elsif language = pathname.language language # Try to detect Language from shebang line diff --git a/lib/linguist/pathname.rb b/lib/linguist/pathname.rb index a8d01aaa..00a10f66 100644 --- a/lib/linguist/pathname.rb +++ b/lib/linguist/pathname.rb @@ -52,25 +52,16 @@ module Linguist # Pathname.new('file.rb').language # # => Language['Ruby'] # - # Returns a Langauge. + # Returns a Langauge or nil if none was found. def language - Language.find_by_filename(@path) || Language['Text'] + @language ||= Language.find_by_filename(@path) end - # Internal: Has a language. - # - # Will return false if language was guessed to be Text. - # - # Returns true or false. - def language? - Language.find_by_filename(@path) ? true : false - end - - # Deprecated: Get the lexer of the path + # Internal: Get the lexer of the path # # Returns a Lexer. def lexer - language.lexer + language ? language.lexer : Lexer['Text only'] end # Public: Get the mime type diff --git a/test/test_pathname.rb b/test/test_pathname.rb index 188912a8..520a6d38 100644 --- a/test/test_pathname.rb +++ b/test/test_pathname.rb @@ -24,7 +24,7 @@ class TestPathname < Test::Unit::TestCase end def test_language - assert_equal Language['Text'], Pathname.new(".rb").language + assert_nil Pathname.new(".rb").language assert_equal Language['Ruby'], Pathname.new("file.rb").language assert_equal Language['Ruby'], Pathname.new("./file.rb").language @@ -37,7 +37,8 @@ class TestPathname < Test::Unit::TestCase assert_equal Language['Gentoo Ebuild'], Pathname.new("file.ebuild").language assert_equal Language['Python'], Pathname.new("itty.py").language assert_equal Language['Nu'], Pathname.new("itty.nu").language - assert_equal Language['Text'], Pathname.new("defun.kt").language + + assert_nil Pathname.new("defun.kt").language end def test_lexer