Skip to content

Commit

Permalink
Actually return the strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
arfon committed Mar 5, 2015
1 parent 1bc1803 commit a1010b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/linguist/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ def self.detect(blob)
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
Expand All @@ -125,7 +126,7 @@ def self.detect(blob)
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
Expand Down
8 changes: 7 additions & 1 deletion test/test_instrumentation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ def test_modeline_instrumentation
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

0 comments on commit a1010b8

Please sign in to comment.