Class: DiffTest::Trackers::RubyFile

Inherits:
Base
  • Object
show all
Defined in:
lib/diff_test/trackers/ruby_file.rb

Constant Summary collapse

@@location_by_constant =
{}

Instance Attribute Summary

Attributes inherited from Base

#impacted_files

Instance Method Summary collapse

Methods inherited from Base

#record

Constructor Details

#initializeRubyFile

Returns a new instance of RubyFile.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/diff_test/trackers/ruby_file.rb', line 7

def initialize
  super
  do_line_check = ENV['DIFF_TEST_SKIP_LINE_CHECK'] != '1'
  @seen_constants = Set.new
  @tracepoint = TracePoint.new(:call, :b_call) do |event|
    if do_line_check && DiffTest::Helper.file_in_project?(event.path)
      record(DiffTest::Helper.relative_path_from_project_root(event.path))
    end

    constant = event.defined_class
    constant = event.self if constant == Class && event.method_id == :new

    unless @seen_constants.include?(constant)
      @seen_constants.add(constant)

      if constant&.singleton_class?
        constant = constant.attached_object if constant&.singleton_class?
        next if constant.__basic_object?
      end

      path = @@location_by_constant[constant]

      if path.nil?
        if constant
          path = begin
            DiffTest::Helper.const_source_path(constant.name)
          rescue StandardError
            nil
          end
        end
        path = false if !path || !DiffTest::Helper.file_in_project?(path)
        path = DiffTest::Helper.relative_path_from_project_root(path) if path
        @@location_by_constant[constant] = path
      end

      record(path) if path
    end
  end
end

Instance Method Details

#pauseObject



61
62
63
# File 'lib/diff_test/trackers/ruby_file.rb', line 61

def pause
  @tracepoint.disable
end

#resumeObject



57
58
59
# File 'lib/diff_test/trackers/ruby_file.rb', line 57

def resume
  @tracepoint.enable
end

#startObject



47
48
49
# File 'lib/diff_test/trackers/ruby_file.rb', line 47

def start
  @tracepoint.enable
end

#stopObject



51
52
53
54
55
# File 'lib/diff_test/trackers/ruby_file.rb', line 51

def stop
  @tracepoint.disable
  @tracepoint = nil
  @seen_constants = nil
end