Class: Timmy::TargetedTimerManager
- Inherits:
-
Object
- Object
- Timmy::TargetedTimerManager
- Defined in:
- lib/timmy/targeted_timer_manager.rb
Class Method Summary collapse
- .start_for_line(line) ⇒ Object
- .started ⇒ Object
- .stop(timer) ⇒ Object
- .stop_all ⇒ Object
- .stop_by_id_and_group(id, group) ⇒ Object
- .stop_for_line(line) ⇒ Object
- .stopped ⇒ Object
Class Method Details
.start_for_line(line) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/timmy/targeted_timer_manager.rb', line 4 def start_for_line(line) TargetedTimerDefinition.all.each do |definition| if match = match_line(line, definition.start_regex) label = get_capture(match, :label) group = get_capture(match, :group) stop_by_id_and_group(definition.id, group) started.push(TargetedTimer.new(definition, label: label, group: group)) end end end |
.started ⇒ Object
46 47 48 |
# File 'lib/timmy/targeted_timer_manager.rb', line 46 def started @started ||= [] end |
.stop(timer) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/timmy/targeted_timer_manager.rb', line 26 def stop(timer) timer.stop Logger.put_timer(timer) started.delete(timer) stopped.push(timer) end |
.stop_all ⇒ Object
42 43 44 |
# File 'lib/timmy/targeted_timer_manager.rb', line 42 def stop_all started.each { |timer| stop(timer) } end |
.stop_by_id_and_group(id, group) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/timmy/targeted_timer_manager.rb', line 34 def stop_by_id_and_group(id, group) matches = started .select { |timer| timer.definition.id } .select { |timer| timer.group == group } matches.each { |timer| stop(timer) } end |
.stop_for_line(line) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/timmy/targeted_timer_manager.rb', line 16 def stop_for_line(line) started.each do |timer| if (stop_regex = timer.definition.stop_regex) && (match = match_line(line, stop_regex)) && get_capture(match, :group) == timer.group stop(timer) end end end |
.stopped ⇒ Object
50 51 52 |
# File 'lib/timmy/targeted_timer_manager.rb', line 50 def stopped @stopped ||= [] end |