mirror of
https://github.com/KevinMidboe/linguist.git
synced 2025-10-29 17:50:22 +00:00
Actually return the strategy
This commit is contained in:
@@ -108,9 +108,10 @@ module Linguist
|
||||
Linguist.instrument("linguist.detection", :blob => blob) do
|
||||
# Call each strategy until one candidate is returned.
|
||||
languages = []
|
||||
strategy = nil
|
||||
returning_strategy = nil
|
||||
|
||||
STRATEGIES.each do |strategy|
|
||||
returning_strategy = strategy
|
||||
candidates = Linguist.instrument("linguist.strategy", :blob => blob, :strategy => strategy, :candidates => languages) do
|
||||
strategy.call(blob, languages)
|
||||
end
|
||||
@@ -125,7 +126,7 @@ module Linguist
|
||||
end
|
||||
end
|
||||
|
||||
Linguist.instrument("linguist.detected", :blob => blob, :strategy => strategy, :language => languages.first)
|
||||
Linguist.instrument("linguist.detected", :blob => blob, :strategy => returning_strategy, :language => languages.first)
|
||||
|
||||
languages.first
|
||||
end
|
||||
|
||||
@@ -38,7 +38,13 @@ class TestInstrumentation < Minitest::Test
|
||||
blob = fixture_blob("Data/Modelines/ruby")
|
||||
Language.detect(blob)
|
||||
|
||||
detect_event = Linguist.instrumenter.events.last
|
||||
detect_event_payload = detect_event[:args].first
|
||||
|
||||
assert_equal 3, Linguist.instrumenter.events.size
|
||||
assert_equal "linguist.detected", Linguist.instrumenter.events.last.name
|
||||
assert_equal "linguist.detected", detect_event.name
|
||||
assert_equal Language['Ruby'], detect_event_payload[:language]
|
||||
assert_equal blob, detect_event_payload[:blob]
|
||||
assert_equal Linguist::Strategy::Modeline, detect_event_payload[:strategy]
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user