diver_down 0.0.1.alpha2 → 0.0.1.alpha3

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diver_down
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha2
4
+ version: 0.0.1.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-15 00:00:00.000000000 Z
11
+ date: 2024-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,7 +38,10 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.3.0
41
- description: ''
41
+ description: DiverDown is a tool designed to dynamically analyze application dependencies
42
+ and generate a comprehensive dependency map. It is particularly useful for analyzing
43
+ Ruby applications, aiding significantly in large-scale refactoring projects or transitions
44
+ towards a modular monolith architecture.
42
45
  email:
43
46
  - alpaca-tc@alpaca.tc
44
47
  executables:
@@ -65,8 +68,8 @@ files:
65
68
  - lib/diver_down/trace/module_set/array_module_set.rb
66
69
  - lib/diver_down/trace/module_set/const_source_location_module_set.rb
67
70
  - lib/diver_down/trace/redefine_ruby_methods.rb
71
+ - lib/diver_down/trace/session.rb
68
72
  - lib/diver_down/trace/tracer.rb
69
- - lib/diver_down/trace/tracer/session.rb
70
73
  - lib/diver_down/version.rb
71
74
  - lib/diver_down/web.rb
72
75
  - lib/diver_down/web/action.rb
@@ -104,5 +107,6 @@ requirements: []
104
107
  rubygems_version: 3.5.5
105
108
  signing_key:
106
109
  specification_version: 4
107
- summary: Tool to dynamically analyze applications and create dependency maps
110
+ summary: dynamically analyze application dependencies and generate a comprehensive
111
+ dependency map
108
112
  test_files: []
@@ -1,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module DiverDown
4
- module Trace
5
- class Tracer
6
- class Session
7
- class NotStarted < StandardError; end
8
-
9
- attr_reader :definition
10
-
11
- # @param [DiverDown::Trace::ModuleSet, nil] module_set
12
- # @param [DiverDown::Trace::IgnoredMethodIds, nil] ignored_method_ids
13
- # @param [Set<String>, nil] target_file_set
14
- # @param [#call, nil] filter_method_id_path
15
- def initialize(module_set: DiverDown::Trace::ModuleSet.new, ignored_method_ids: nil, target_file_set: nil, filter_method_id_path: nil, definition: DiverDown::Definition.new)
16
- @module_set = module_set
17
- @ignored_method_ids = ignored_method_ids
18
- @target_file_set = target_file_set
19
- @filter_method_id_path = filter_method_id_path
20
- @definition = definition
21
- @trace_point = build_trace_point
22
- end
23
-
24
- # @return [void]
25
- def start
26
- @trace_point.enable
27
- end
28
-
29
- # @return [void]
30
- def stop
31
- @trace_point.disable
32
- end
33
-
34
- private
35
-
36
- def build_trace_point
37
- call_stack = DiverDown::Trace::CallStack.new
38
- ignored_stack_size = nil
39
-
40
- TracePoint.new(*DiverDown::Trace::Tracer.trace_events) do |tp|
41
- # Skip the trace of the library itself
42
- next if tp.path&.start_with?(DiverDown::LIB_DIR)
43
- next if TracePoint == tp.defined_class
44
-
45
- case tp.event
46
- when :call, :c_call
47
- # puts "#{tp.method_id} #{tp.path}:#{tp.lineno}"
48
- mod = DiverDown::Helper.resolve_module(tp.self)
49
- source_name = DiverDown::Helper.normalize_module_name(mod) if !mod.nil? && @module_set.include?(mod)
50
- already_ignored = !ignored_stack_size.nil? # If the current method_id is ignored
51
- current_ignored = !@ignored_method_ids.nil? && @ignored_method_ids.ignored?(mod, DiverDown::Helper.module?(tp.self), tp.method_id)
52
- pushed = false
53
-
54
- if !source_name.nil? && !(already_ignored || current_ignored)
55
- source = @definition.find_or_build_source(source_name)
56
-
57
- # If the call stack contains a call to a module to be traced
58
- # `@ignored_call_stack` is not nil means the call stack contains a call to a module to be ignored
59
- unless call_stack.empty?
60
- # Add dependency to called source
61
- called_stack_context = call_stack.stack[-1]
62
- called_source = called_stack_context.source
63
- dependency = called_source.find_or_build_dependency(source_name)
64
-
65
- # `dependency.nil?` means source_name equals to called_source.source.
66
- # self-references are not tracked because it is not "dependency".
67
- if dependency
68
- context = DiverDown::Helper.module?(tp.self) ? 'class' : 'instance'
69
- method_id = dependency.find_or_build_method_id(name: tp.method_id, context:)
70
- method_id_path = "#{called_stack_context.caller_location.path}:#{called_stack_context.caller_location.lineno}"
71
- method_id_path = @filter_method_id_path.call(method_id_path) if @filter_method_id_path
72
- method_id.add_path(method_id_path)
73
- end
74
- end
75
-
76
- # `caller_location` is nil if it is filtered by target_files
77
- caller_location = find_neast_caller_location
78
-
79
- if caller_location
80
- pushed = true
81
-
82
- call_stack.push(
83
- StackContext.new(
84
- source:,
85
- method_id: tp.method_id,
86
- caller_location:
87
- )
88
- )
89
- end
90
- end
91
-
92
- call_stack.push unless pushed
93
-
94
- # If a value is already stored, it means that call stack already determined to be ignored at the shallower call stack size.
95
- # Since stacks deeper than the shallowest stack size are ignored, priority is given to already stored values.
96
- if !already_ignored && current_ignored
97
- ignored_stack_size = call_stack.stack_size
98
- end
99
- when :return, :c_return
100
- ignored_stack_size = nil if ignored_stack_size == call_stack.stack_size
101
- call_stack.pop
102
- end
103
- rescue StandardError
104
- tp.disable
105
- raise
106
- end
107
- end
108
-
109
- def find_neast_caller_location
110
- return caller_locations(2, 2)[0] if @target_file_set.nil?
111
-
112
- Thread.each_caller_location do
113
- return _1 if @target_file_set.include?(_1.path)
114
- end
115
-
116
- nil
117
- end
118
- end
119
- end
120
- end
121
- end