mirror of
https://github.com/KevinMidboe/linguist.git
synced 2026-01-02 07:26:18 +00:00
Store md5 in samples db
This commit is contained in:
@@ -18,13 +18,6 @@ module Linguist
|
|||||||
DATA = nil
|
DATA = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if serialized db is out of sync from db directory.
|
|
||||||
#
|
|
||||||
# Returns Boolean.
|
|
||||||
def self.outdated?
|
|
||||||
MD5.hexdigest(DATA) != MD5.hexdigest(data)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Public: Iterate over each sample.
|
# Public: Iterate over each sample.
|
||||||
#
|
#
|
||||||
# &block - Yields Sample to block
|
# &block - Yields Sample to block
|
||||||
@@ -108,6 +101,7 @@ module Linguist
|
|||||||
data = File.read(sample[:path])
|
data = File.read(sample[:path])
|
||||||
Classifier.train!(db, language.name, data)
|
Classifier.train!(db, language.name, data)
|
||||||
end
|
end
|
||||||
|
db['md5'] = MD5.hexdigest(db)
|
||||||
db
|
db
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -120,6 +114,8 @@ module Linguist
|
|||||||
out = ""
|
out = ""
|
||||||
escape = lambda { |s| s.inspect.gsub(/\\#/, "\#") }
|
escape = lambda { |s| s.inspect.gsub(/\\#/, "\#") }
|
||||||
|
|
||||||
|
out << "md5: #{db['md5']}\n"
|
||||||
|
|
||||||
out << "languages_total: #{db['languages_total']}\n"
|
out << "languages_total: #{db['languages_total']}\n"
|
||||||
out << "tokens_total: #{db['tokens_total']}\n"
|
out << "tokens_total: #{db['tokens_total']}\n"
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
md5: b445a8a3e3414d6b628939c347e7a4f3
|
||||||
languages_total: 243
|
languages_total: 243
|
||||||
tokens_total: 164127
|
tokens_total: 164127
|
||||||
languages:
|
languages:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class TestClassifier < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_instance_freshness
|
def test_instance_freshness
|
||||||
# Just warn, it shouldn't scare people off by breaking the build.
|
# Just warn, it shouldn't scare people off by breaking the build.
|
||||||
if Samples.outdated?
|
if Samples::DATA['md5'] != Samples.data['md5']
|
||||||
warn "Classifier database is out of date. Run `bundle exec rake classifier`."
|
warn "Classifier database is out of date. Run `bundle exec rake classifier`."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user