Class: Pask::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/pask/event.rb

Constant Summary collapse

CALL =
"call"
C_CALL =
"c-call"
RETURN =
"return"
C_RETURN =
"c-return"
KNOWN_NAMES =
[CALL, C_CALL, RETURN, C_RETURN].map!(&:freeze)

Instance Method Summary collapse

Constructor Details

#initialize(name, other) ⇒ Event

Returns a new instance of Event.



8
9
10
11
12
13
14
15
# File 'lib/pask/event.rb', line 8

def initialize(name, other)
  @name = name
  @other = other
  @created_at = Time.now
  @signature = nil
  @to_f = nil
  @emit_by = binding.eval "self"
end

Instance Method Details

#-(other) ⇒ Object



90
91
92
93
94
95
# File 'lib/pask/event.rb', line 90

def -(other)
  unless other.respond_to?(:to_f)
    raise TypeError, "cannot coerce argument to a float"
  end
  to_f - other.to_f
end

#__binding__Object



46
47
48
# File 'lib/pask/event.rb', line 46

def __binding__
  Kernel.binding
end

#any_call?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/pask/event.rb', line 50

def any_call?
  call? or c_call?
end

#any_return?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/pask/event.rb', line 70

def any_return?
  return? or c_return?
end

#bindingObject



42
43
44
# File 'lib/pask/event.rb', line 42

def binding
  @other[:binding]
end

#c_call?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/pask/event.rb', line 66

def c_call?
  @name == C_CALL
end

#c_return?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/pask/event.rb', line 58

def c_return?
  @name == C_RETURN
end

#call?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/pask/event.rb', line 62

def call?
  @name == CALL
end

#created_atObject



26
27
28
# File 'lib/pask/event.rb', line 26

def created_at
  @created_at
end

#emit_byObject



17
18
19
20
# File 'lib/pask/event.rb', line 17

def emit_by
  # FIXME: messed up for C calls and returns. maybe return nil for them?
  @emit_by
end

#emit_by_methodObject



38
39
40
# File 'lib/pask/event.rb', line 38

def emit_by_method
  @other[:method]
end

#fileObject



30
31
32
# File 'lib/pask/event.rb', line 30

def file
  @other[:file]
end

#linenoObject



34
35
36
# File 'lib/pask/event.rb', line 34

def lineno
  @other[:lineno]
end

#origin?(mod) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
80
# File 'lib/pask/event.rb', line 74

def origin?(mod)
  if emit_by.respond_to?(:ancestors)
    emit_by.ancestors.include?(mod)
  else
    mod === emit_by
  end
end

#return?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/pask/event.rb', line 54

def return?
  @name == RETURN
end

#signatureObject



82
83
84
85
86
87
88
# File 'lib/pask/event.rb', line 82

def signature
  @signature ||= if emit_by.kind_of?(Module)
    [emit_by, @method].join(".")
  else
    [emit_by.class, @method].join("#")
  end
end

#to_fObject



22
23
24
# File 'lib/pask/event.rb', line 22

def to_f
  @to_f ||= @created_at.to_f
end