Class: Minstrel::Instrument
- Inherits:
-
Object
- Object
- Minstrel::Instrument
- Defined in:
- lib/minstrel.rb
Overview
class Minstrel::Event
Instance Attribute Summary collapse
-
#counter ⇒ Object
Returns the value of attribute counter.
Class Method Summary collapse
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
-
#initialize ⇒ Instrument
constructor
A new instance of Instrument.
- #observe(thing = nil, &block) ⇒ Object
- #stack ⇒ Object
Constructor Details
#initialize ⇒ Instrument
Returns a new instance of Instrument.
112 113 114 115 |
# File 'lib/minstrel.rb', line 112 def initialize @observe = [] @stack = Hash.new { |h,k| h[k] = [] } # per thread end |
Instance Attribute Details
#counter ⇒ Object
Returns the value of attribute counter.
104 105 106 |
# File 'lib/minstrel.rb', line 104 def counter @counter end |
Class Method Details
.singleton ⇒ Object
107 108 109 |
# File 'lib/minstrel.rb', line 107 def self.singleton @minstrel ||= Minstrel::Instrument.new end |
Instance Method Details
#disable ⇒ Object
170 171 172 |
# File 'lib/minstrel.rb', line 170 def disable set_trace_func(nil) end |
#enable ⇒ Object
164 165 166 |
# File 'lib/minstrel.rb', line 164 def enable set_trace_func(Proc.new { |*args| trace_callback(*args) }) end |
#observe(thing = nil, &block) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/minstrel.rb', line 123 def observe(thing=nil, &block) if !thing.nil? # Is thing a class name? @observe << lambda do |event| if class?(thing) if event.class.to_s == thing.to_s block.call(event) end else # assume it's a method? #p :observe => nil, :class => thing, :is => class?(thing) klass, method = thing.split(/[.#]/, 2) if (event.class.to_s == klass and event.method = method.to_sym) block.call(event) end end end elsif block_given? @observe << block else raise ArgumentError.new("No block given.") end end |
#stack ⇒ Object
118 119 120 |
# File 'lib/minstrel.rb', line 118 def stack return @stack end |