Class: Derketo::Event

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/derketo/events/event.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#clean, write

Constructor Details

#initialize(tracepoint) ⇒ Event

Returns a new instance of Event.



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

def initialize(tracepoint)
  @class_name = clean(tracepoint.defined_class.to_s)
  @return_value = tracepoint.event == :return ? clean(tracepoint.return_value.to_s) : nil
  @type = tracepoint.event
  @method_id = clean(tracepoint.method_id.to_s)
  @parameters = tracepoint.self.method(tracepoint.method_id).parameters
  @previous = self
end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def class_name
  @class_name
end

#method_idObject

Returns the value of attribute method_id.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def method_id
  @method_id
end

#nextObject

Returns the value of attribute next.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def next
  @next
end

#parametersObject

Returns the value of attribute parameters.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def parameters
  @parameters
end

#previousObject

Returns the value of attribute previous.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def previous
  @previous
end

#return_valueObject

Returns the value of attribute return_value.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def return_value
  @return_value
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/derketo/events/event.rb', line 6

def type
  @type
end

Instance Method Details

#to_hObject



17
18
19
20
21
22
23
24
25
# File 'lib/derketo/events/event.rb', line 17

def to_h
  {
    class: @class_name,
    type: @type,
    method: @method_id,
    parameters: @parameters,
    return_value: @return_value
  }
end

#to_jsonObject

{ "class": "Mermaid", "type": "call", "method": "initialize", "parameters": [], "return_value": null }



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

def to_json
  JSON.generate(to_h)
end

#to_sObject

{ :class=>"Mermaid", :type=>:call, :method=>:initialize, :parameters=>[], :return_value=>nil }



45
46
47
# File 'lib/derketo/events/event.rb', line 45

def to_s
  to_h.to_s
end