Class: RShade::Event

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

Overview

nodoc

Constant Summary collapse

RETURN_EVENTS =
[:return, :b_return, :c_return]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Event

Returns a new instance of Event.



8
9
10
# File 'lib/rshade/event.rb', line 8

def initialize(hash)
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'lib/rshade/event.rb', line 4

def hash
  @hash
end

#skippedObject (readonly)

Returns the value of attribute skipped.



4
5
6
# File 'lib/rshade/event.rb', line 4

def skipped
  @skipped
end

Class Method Details

.from_trace_point(evt) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rshade/event.rb', line 38

def self.from_trace_point(evt)
  vars = {}
  evt.binding.local_variables.each do |var_name|
    vars[var_name] = evt.binding.local_variable_get var_name
  end

  hash = { path: evt.path, lineno: evt.lineno, klass: evt.defined_class, method_name: evt.method_id, vars: vars,
           event_type: evt.event }
  hash.merge!({return_value: evt.return_value}) if RETURN_EVENTS.include?(evt.event)
  new(hash)
end

Instance Method Details

#set_return_value!(return_value) ⇒ Object



23
24
25
26
# File 'lib/rshade/event.rb', line 23

def set_return_value!(return_value)
  @hash[:return_value] = return_value
  self
end

#with_level!(level) ⇒ Object



18
19
20
21
# File 'lib/rshade/event.rb', line 18

def with_level!(level)
  @hash[:level] = level
  self
end

#with_serialized_return!(serializer) ⇒ Object



28
29
30
31
# File 'lib/rshade/event.rb', line 28

def with_serialized_return!(serializer)
  @hash[:return_value] = serializer.call(@hash[:return_value])
  self
end

#with_serialized_vars!(serializer) ⇒ Object



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

def with_serialized_vars!(serializer)
  @hash[:vars] = serializer.call(@hash[:vars])
  self
end