Skip to content
Browse files

test and fix top-level interface

  • Loading branch information...
1 parent 4ec734d commit 95a16a4c4e002d2f88659236398e503ce013a7a5 @grosser committed Sep 17, 2011
Showing with 10 additions and 7 deletions.
  1. +4 −0 README.md
  2. +2 −3 lib/language_sniffer.rb
  3. +4 −4 test/test_sniffer.rb
View
4 README.md
@@ -15,6 +15,10 @@ Most languages are detected by their file extension. This is the fastest and mos
LanguageSniffer.detect("bin/language_sniffer").language.name #=> "Ruby"
+You can also just pass :content and :path, no need to have a local file.
+
+ LanguageSniffer.detect("xxx/language_sniffer", :content => File.read('bin/language_sniffer)).language.name #=> "Ruby"
+
See [lib/language_sniffer/language.rb](https://github.com/grosser/language_sniffer/blob/master/lib/language_sniffer/language.rb) and [lib/language_sniffer/languages.yml](https://github.com/github/language_sniffer/blob/master/lib/language_sniffer/languages.yml).
## Installation
View
5 lib/language_sniffer.rb
@@ -4,8 +4,7 @@
require 'language_sniffer/pathname'
module LanguageSniffer
- def self.detect(options)
- raise "I need :path" if not options[:path]
- FileBlob.new(options[:path], options[:pwd], options[:content])
+ def self.detect(path, options={})
+ FileBlob.new(path, options[:pwd], options[:content])
end
end
View
8 test/test_sniffer.rb
@@ -4,15 +4,15 @@
class TestSniffer < Test::Unit::TestCase
def test_sniffer
# path and content given -> does not read file
- assert_equal 'Ruby', LanguageSniffer.detect(:path => 'foo/bar', :content => '#!/usr/bin/env ruby').language.name
+ assert_equal 'Ruby', LanguageSniffer.detect('foo/bar', :content => '#!/usr/bin/env ruby').language.name
# pure un-descriptive path -> reads file
- assert_equal 'Ruby', LanguageSniffer.detect(:path => 'bin/language_sniffer').language.name
+ assert_equal 'Ruby', LanguageSniffer.detect('bin/language_sniffer').language.name
# pure descriptive path -> does not need to read file
- assert_equal 'Ruby', LanguageSniffer.detect(:path => 'foo/bar.rb').language.name
+ assert_equal 'Ruby', LanguageSniffer.detect('foo/bar.rb').language.name
# empty
- assert_equal nil, LanguageSniffer.detect(:path => 'test/fixtures/blank').language
+ assert_equal nil, LanguageSniffer.detect('test/fixtures/blank').language
end
end

0 comments on commit 95a16a4

Please sign in to comment.
Something went wrong with that request. Please try again.