class Pask
Constants
- CATCH_ALL
- NotFinishedError
- NotStartedError
- RUN_STATE
- SLEEP_STATE
- TERMINATED_STATE
- VERSION
Public Class Methods
new()
click to toggle source
# File lib/pask.rb, line 18 def initialize @thread = nil @queue = nil @predicate = CATCH_ALL @predicate_copy = nil @block = nil @block_copy = nil end
version()
click to toggle source
# File lib/pask.rb, line 14 def self.version VERSION end
Public Instance Methods
consume!()
click to toggle source
# File lib/pask.rb, line 96 def consume! events = [start] current_event = nil events.push(current_event) while current_event = resume events end
finished?()
click to toggle source
# File lib/pask.rb, line 51 def finished? if @thread and TERMINATED_STATE.include?(@thread.status) true else false end end
interested?(callable = nil, &block)
click to toggle source
# File lib/pask.rb, line 27 def interested?(callable = nil, &block) predicate = callable || block unless predicate raise ArgumentError, "no predicate given to #{__method__}()" end @predicate = predicate end
resume()
click to toggle source
# File lib/pask.rb, line 67 def resume unless started? raise NotStartedError, "tracer has not been started" end if sleeping? @thread.wakeup @queue.deq end end
running?()
click to toggle source
# File lib/pask.rb, line 43 def running? if @thread and @thread.status == RUN_STATE true else false end end
sleeping?()
click to toggle source
# File lib/pask.rb, line 59 def sleeping? if @thread and @thread.status == SLEEP_STATE true else false end end
start()
click to toggle source
# File lib/pask.rb, line 77 def start if started? and not finished? raise NotFinishedError, "tracer has not finished" end @queue = Queue.new @thread = Thread.new do @predicate_copy, @block_copy = @predicate, @block Thread.current.set_trace_func method(:on_event).to_proc @block_copy.call Thread.current.set_trace_func(nil) @queue.enq nil end @queue.deq end
started?()
click to toggle source
# File lib/pask.rb, line 35 def started? if @queue and @thread true else false end end
trace(&block)
click to toggle source
# File lib/pask.rb, line 92 def trace(&block) @block = block end
Private Instance Methods
on_event(name, file, lineno, method, binding, _)
click to toggle source
# File lib/pask.rb, line 104 def on_event(name, file, lineno, method, binding, _) event = Event.new name, file: file, method: method, lineno: lineno, binding: binding if event.file != __FILE__ and @predicate_copy.call(event) @queue.enq(event) Thread.stop end rescue Exception => e warn "TRACER CRASHED" Thread.current.set_trace_func(nil) end