Class: Warp::Instrument

Inherits:
Object
  • Object
show all
Defined in:
lib/warp/instrument.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, method) ⇒ Instrument

Returns a new instance of Instrument.



21
22
23
24
25
26
27
28
29
# File 'lib/warp/instrument.rb', line 21

def initialize(klass, method)
  self.klass = klass
  self.method = method
  self.enabled = false
  self.calls = []
  setup_hook

  self.class.send(:register, self)
end

Instance Attribute Details

#callsObject

Returns the value of attribute calls.



19
20
21
# File 'lib/warp/instrument.rb', line 19

def calls
  @calls
end

#enabledObject

Returns the value of attribute enabled.



19
20
21
# File 'lib/warp/instrument.rb', line 19

def enabled
  @enabled
end

#klassObject

Returns the value of attribute klass.



19
20
21
# File 'lib/warp/instrument.rb', line 19

def klass
  @klass
end

#methodObject

Returns the value of attribute method.



19
20
21
# File 'lib/warp/instrument.rb', line 19

def method
  @method
end

Class Method Details

.for(klass, method) ⇒ Object



4
5
6
7
8
# File 'lib/warp/instrument.rb', line 4

def for(klass, method)
  @@registry ||= {}
  @@registry[klass] ||= {}
  @@registry[klass][method] || new(klass, method)
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/warp/instrument.rb', line 41

def enabled?
  enabled
end

#log(args) ⇒ Object



45
46
47
# File 'lib/warp/instrument.rb', line 45

def log(args)
  calls << args if enabled?
end

#resetObject



31
32
33
# File 'lib/warp/instrument.rb', line 31

def reset
  self.calls = []
end

#runObject



35
36
37
38
39
# File 'lib/warp/instrument.rb', line 35

def run
  enable
  yield
  disable
end