Class: Rookout::Services::PositionResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/rookout/services/position.rb

Instance Method Summary collapse

Constructor Details

#initialize(tracer) ⇒ PositionResolver

Returns a new instance of PositionResolver.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rookout/services/position.rb', line 19

def initialize tracer
  @tracer = tracer
  @augs = {}
  @augs_lock = Mutex.new
  @iseqs = []
  @trace_point = TracePoint.new :script_compiled do |tp|
    begin
      begin
        iseq = tp.instruction_sequence
        # Ignore script without sources
        if iseq.absolute_path
          @iseqs << iseq
          evaluate_script iseq
        end
      rescue Exception => e
        Logger.instance.exception "Exception while evaluating script", e
      end
    rescue
    end
  end

  @trace_point.enable
end

Instance Method Details

#add_aug(location) ⇒ Object



43
44
45
46
47
# File 'lib/rookout/services/position.rb', line 43

def add_aug location
  positions = evaluate_all_scripts_to_location location
  @tracer.add_breakpoint_aug positions, location unless positions.empty?
  @augs_lock.synchronize { @augs[location.id] = location }
end

#clear_augsObject



57
58
59
60
61
62
63
# File 'lib/rookout/services/position.rb', line 57

def clear_augs
  @augs.each_value do |aug_id|
    remove_aug aug_id
  end

  @augs = {}
end

#closeObject



65
66
67
68
# File 'lib/rookout/services/position.rb', line 65

def close
  clear_augs
  @trace_point.disable
end

#remove_aug(aug_id) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/rookout/services/position.rb', line 49

def remove_aug aug_id
  location = @augs[aug_id]
  return if location.nil?

  @augs.delete [aug_id]
  location.notify_removed
end