diff --git a/lib/linguist/classifier.rb b/lib/linguist/classifier.rb index c690b6b9..4ab6d191 100644 --- a/lib/linguist/classifier.rb +++ b/lib/linguist/classifier.rb @@ -29,6 +29,19 @@ module Linguist @languages = Hash.new(0) end + # Public: Compare Classifier objects. + # + # other - Classifier object to compare to. + # + # Returns Boolean. + def eql?(other) + # Lazy fast check counts only + other.is_a?(self.class) && + @tokens_total == other.instance_variable_get(:@tokens_total) && + @languages_total == other.instance_variable_get(:@languages_total) + end + alias_method :==, :eql? + # Public: Train classifier that data is a certain language. # # language - Language of data diff --git a/test/test_classifier.rb b/test/test_classifier.rb index bac2efa1..9c0328b6 100644 --- a/test/test_classifier.rb +++ b/test/test_classifier.rb @@ -16,6 +16,13 @@ class TestClassifier < Test::Unit::TestCase File.read(File.join(fixtures_path, name)) end + def test_instance_freshness + # Just warn, it shouldn't scare people off by breaking the build. + unless Classifier.instance.eql?(Linguist::Sample.classifier) + warn "Classifier database is out of date. Run `bundle exec rake classifier`." + end + end + def test_classify classifier = Classifier.new classifier.train Language["Ruby"], fixture("ruby/foo.rb")