Class: Uncool::Trace
- Inherits:
-
Object
- Object
- Uncool::Trace
- Defined in:
- lib/uncool/trace.rb
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
Instance Method Summary collapse
- #activate ⇒ Object
- #deactivate ⇒ Object
-
#initialize(targets, options = {}) ⇒ Trace
constructor
A new instance of Trace.
- #setup ⇒ Object
- #target?(mod) ⇒ Boolean
- #to_analysis ⇒ Object
Constructor Details
#initialize(targets, options = {}) ⇒ Trace
Returns a new instance of Trace.
19 20 21 22 23 |
# File 'lib/uncool/trace.rb', line 19 def initialize(targets, ={}) @targets = [targets].compact.flatten @options = @log = [] end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
16 17 18 |
# File 'lib/uncool/trace.rb', line 16 def log @log end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
13 14 15 |
# File 'lib/uncool/trace.rb', line 13 def targets @targets end |
Instance Method Details
#activate ⇒ Object
53 54 55 56 |
# File 'lib/uncool/trace.rb', line 53 def activate setup TracePoint.activate end |
#deactivate ⇒ Object
59 60 61 |
# File 'lib/uncool/trace.rb', line 59 def deactivate TracePoint.deactivate end |
#setup ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/uncool/trace.rb', line 26 def setup tracker = self TracePoint.trace do |tp| #puts "#{tp.self.class}\t#{tp.callee}\t#{tp.event}\t#{tp.return?}" if tp.event == 'call' or tp.event == 'c-call' if tracker.target?(tp.self.class) tracker.log << [tp.self, tp.callee] end end end end |
#target?(mod) ⇒ Boolean
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/uncool/trace.rb', line 39 def target?(mod) return true if targets.empty? targets.find do |target| begin target_class = eval(target, TOPLEVEL_BINDING) #Object.const_get(target) rescue nil else target_class == mod end end end |