diver_down 0.0.1.alpha12 → 0.0.1.alpha14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/exe/diver_down_web +4 -4
- data/lib/diver_down/definition/dependency.rb +10 -0
- data/lib/diver_down/definition/method_id.rb +6 -0
- data/lib/diver_down/definition/source.rb +13 -0
- data/lib/diver_down/definition.rb +8 -0
- data/lib/diver_down/version.rb +1 -1
- data/lib/diver_down/web/action.rb +119 -34
- data/lib/diver_down/web/definition_store.rb +20 -2
- data/lib/diver_down/web/definition_to_dot.rb +86 -74
- data/lib/diver_down/web/metadata/source_alias.rb +128 -0
- data/lib/diver_down/web/metadata/source_metadata.rb +59 -0
- data/lib/diver_down/web/metadata.rb +66 -0
- data/lib/diver_down/web/module_sources_filter.rb +54 -0
- data/lib/diver_down/web/source_alias_resolver.rb +46 -0
- data/lib/diver_down/web.rb +24 -5
- data/web/assets/CFQbqqGu.css +1 -0
- data/web/assets/bundle.js +191 -163
- data/web/index.html +1 -1
- metadata +8 -4
- data/lib/diver_down/web/module_store.rb +0 -92
- data/web/assets/CjLq7LhZ.css +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12f54ddda5108f877d6e1510710b5a397dfc92db94c21f6521739b5032e4351f
|
4
|
+
data.tar.gz: 4c3c4b1063fd4da506077a8f9908a9f621336ffed58e0f5fc8b4c9c5b54cbd15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 476bee3370a190cb94adb215abe7c58deb8c0dac475fca258c9e673d09471c477f5ba7826ba2575524c0f80c1f5454236bb71fd244c8306d02d75ad7766e85b9
|
7
|
+
data.tar.gz: 2e155be624f952d2b0e69d8d9a5ec549053e7f2ddfa469c2ce998777421cab30a73a423a2ecba5264f1fe7e603c4186413a801dfcbe49e82ca39d8bad7ec4531
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Or install it yourself as:
|
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
28
|
-
`
|
28
|
+
`diver_down` is mainly divided into the `DiverDown::Trace` for dynamic analysing ruby code, and the `DiverDown::Web` for viewing the result on the browser.
|
29
29
|
|
30
30
|
### `DiverDown::Trace`
|
31
31
|
|
@@ -121,10 +121,10 @@ View the analysis results in a browser.
|
|
121
121
|
This gem is specifically designed to analyze large applications with a modular monolithic architecture. It allows users to categorize each analyzed file into specified modules directly through the web interface.
|
122
122
|
|
123
123
|
- `--definition-dir` Specifies the directory where the analysis results are stored.
|
124
|
-
- `--
|
124
|
+
- `--metadata` Designates a path to save the results that include details on which module each file belongs to. If this option is not specified, the results will be temporarily stored in a default temporary file.
|
125
125
|
|
126
126
|
```sh
|
127
|
-
bundle exec diver_down_web --definition-dir tmp/diver_down --
|
127
|
+
bundle exec diver_down_web --definition-dir tmp/diver_down --metadata tmp/metadata.yml
|
128
128
|
open http://localhost:8080
|
129
129
|
```
|
130
130
|
|
@@ -151,7 +151,7 @@ $ pnpm run dev
|
|
151
151
|
|
152
152
|
# Start server for backend
|
153
153
|
$ bundle install
|
154
|
-
$ DIVER_DOWN_DIR=/path/to/definitions_dir
|
154
|
+
$ DIVER_DOWN_DIR=/path/to/definitions_dir DIVER_DOWN_METADATA=/path/to/metadata.yml bundle exec puma
|
155
155
|
```
|
156
156
|
|
157
157
|
## Contributing
|
data/exe/diver_down_web
CHANGED
@@ -14,7 +14,7 @@ option_parser = OptionParser.new do |opts|
|
|
14
14
|
Usage: diver_down_web [options]
|
15
15
|
|
16
16
|
Example:
|
17
|
-
diver_down_web --definition-dir /path/to/definitions --
|
17
|
+
diver_down_web --definition-dir /path/to/definitions --metadata /path/to/metadata.yml
|
18
18
|
|
19
19
|
Options:
|
20
20
|
BANNER
|
@@ -23,8 +23,8 @@ option_parser = OptionParser.new do |opts|
|
|
23
23
|
options[:definition_dir] = path
|
24
24
|
end
|
25
25
|
|
26
|
-
opts.on('--
|
27
|
-
options[:
|
26
|
+
opts.on('--metadata PATH', 'Path to the metadata.yml') do |path|
|
27
|
+
options[:metadata] = path
|
28
28
|
end
|
29
29
|
end
|
30
30
|
option_parser.parse!(ARGV)
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
app = Rack::JSONBodyParser.new(
|
40
40
|
DiverDown::Web.new(
|
41
41
|
definition_dir: options.fetch(:definition_dir),
|
42
|
-
|
42
|
+
metadata: DiverDown::Web::Metadata.new(options[:metadata] || Tempfile.new(['metadata', '.yaml']).path)
|
43
43
|
)
|
44
44
|
)
|
45
45
|
|
@@ -102,6 +102,16 @@ module DiverDown
|
|
102
102
|
def inspect
|
103
103
|
%(#<#{self.class} source_name="#{source_name}" method_ids=#{method_ids}>")
|
104
104
|
end
|
105
|
+
|
106
|
+
# @return [void]
|
107
|
+
def freeze
|
108
|
+
super
|
109
|
+
@method_id_map.transform_values do
|
110
|
+
_1.transform_values(&:freeze)
|
111
|
+
_1.freeze
|
112
|
+
end
|
113
|
+
@method_id_map.freeze
|
114
|
+
end
|
105
115
|
end
|
106
116
|
end
|
107
117
|
end
|
@@ -52,6 +52,12 @@ module DiverDown
|
|
52
52
|
@dependency_map[dependency_source_name]
|
53
53
|
end
|
54
54
|
|
55
|
+
# @param dependency_source_name [String]
|
56
|
+
# @return [void]
|
57
|
+
def delete_dependency(dependency_source_name)
|
58
|
+
@dependency_map.delete(dependency_source_name)
|
59
|
+
end
|
60
|
+
|
55
61
|
# @return [Array<DiverDown::Definition::Dependency>]
|
56
62
|
def dependencies
|
57
63
|
@dependency_map.values.sort
|
@@ -85,6 +91,13 @@ module DiverDown
|
|
85
91
|
def hash
|
86
92
|
[self.class, source_name, dependencies].hash
|
87
93
|
end
|
94
|
+
|
95
|
+
# @return [void]
|
96
|
+
def freeze
|
97
|
+
super
|
98
|
+
@dependency_map.transform_values(&:freeze)
|
99
|
+
@dependency_map.freeze
|
100
|
+
end
|
88
101
|
end
|
89
102
|
end
|
90
103
|
end
|
data/lib/diver_down/version.rb
CHANGED
@@ -13,14 +13,50 @@ module DiverDown
|
|
13
13
|
)
|
14
14
|
|
15
15
|
# @param store [DiverDown::Definition::Store]
|
16
|
-
# @param
|
16
|
+
# @param metadata [DiverDown::Web::Metadata]
|
17
17
|
# @param request [Rack::Request]
|
18
|
-
def initialize(store:,
|
18
|
+
def initialize(store:, metadata:, request:)
|
19
19
|
@store = store
|
20
|
-
@
|
20
|
+
@metadata = metadata
|
21
|
+
@source_alias_resolver = DiverDown::Web::SourceAliasResolver.new(@metadata.source_alias)
|
21
22
|
@request = request
|
22
23
|
end
|
23
24
|
|
25
|
+
# GET /api/source_aliases.json
|
26
|
+
def source_aliases
|
27
|
+
source_aliases = @metadata.source_alias.to_h.map do |alias_name, source_names|
|
28
|
+
{
|
29
|
+
alias_name:,
|
30
|
+
source_names:,
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
json(
|
35
|
+
source_aliases:
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
# POST /api/source_aliases.json
|
40
|
+
# @param alias_name [String]
|
41
|
+
# @param old_alias_name [String]
|
42
|
+
# @param source_names [Array<String>]
|
43
|
+
def update_source_alias(alias_name, old_alias_name, source_names)
|
44
|
+
@metadata.source_alias.transaction do
|
45
|
+
unless old_alias_name.to_s.empty?
|
46
|
+
# Delete old alias
|
47
|
+
@metadata.source_alias.update_alias(old_alias_name, [])
|
48
|
+
end
|
49
|
+
|
50
|
+
@metadata.source_alias.update_alias(alias_name, source_names)
|
51
|
+
end
|
52
|
+
|
53
|
+
@metadata.flush
|
54
|
+
|
55
|
+
json({})
|
56
|
+
rescue DiverDown::Web::Metadata::SourceAlias::ConflictError => e
|
57
|
+
json_error(e.message)
|
58
|
+
end
|
59
|
+
|
24
60
|
# GET /api/sources.json
|
25
61
|
def sources
|
26
62
|
source_names = Set.new
|
@@ -33,14 +69,17 @@ module DiverDown
|
|
33
69
|
end
|
34
70
|
# rubocop:enable Style/HashEachMethods
|
35
71
|
|
36
|
-
classified_sources_count = source_names.count { @
|
72
|
+
classified_sources_count = source_names.count { @metadata.source(_1).modules? }
|
37
73
|
|
38
74
|
json(
|
39
75
|
sources: source_names.sort.map do |source_name|
|
76
|
+
source_metadata = @metadata.source(source_name)
|
77
|
+
|
40
78
|
{
|
41
79
|
source_name:,
|
42
|
-
|
43
|
-
|
80
|
+
resolved_alias: @metadata.source_alias.resolve_alias(source_name),
|
81
|
+
memo: source_metadata.memo,
|
82
|
+
modules: source_metadata.modules.map do |module_name|
|
44
83
|
{ module_name: }
|
45
84
|
end,
|
46
85
|
}
|
@@ -57,7 +96,7 @@ module DiverDown
|
|
57
96
|
# rubocop:disable Style/HashEachMethods
|
58
97
|
@store.each do |_, definition|
|
59
98
|
definition.sources.each do |source|
|
60
|
-
modules = @
|
99
|
+
modules = @metadata.source(source.source_name).modules
|
61
100
|
module_set.add(modules) unless modules.empty?
|
62
101
|
end
|
63
102
|
end
|
@@ -84,7 +123,7 @@ module DiverDown
|
|
84
123
|
# rubocop:disable Style/HashEachMethods
|
85
124
|
@store.each do |_, definition|
|
86
125
|
definition.sources.each do |source|
|
87
|
-
source_module_names = @
|
126
|
+
source_module_names = @metadata.source(source.source_name).modules
|
88
127
|
|
89
128
|
next unless source_module_names[0..module_names.size - 1] == module_names
|
90
129
|
|
@@ -109,7 +148,7 @@ module DiverDown
|
|
109
148
|
sources: source_names.sort.map do |source_name|
|
110
149
|
{
|
111
150
|
source_name:,
|
112
|
-
memo: @
|
151
|
+
memo: @metadata.source(source_name).memo,
|
113
152
|
}
|
114
153
|
end,
|
115
154
|
related_definitions: related_definitions.map do |definition|
|
@@ -139,7 +178,7 @@ module DiverDown
|
|
139
178
|
definition_group: definition.definition_group,
|
140
179
|
title: definition.title,
|
141
180
|
sources_count: definition.sources.size,
|
142
|
-
unclassified_sources_count: definition.sources.reject { @
|
181
|
+
unclassified_sources_count: definition.sources.reject { @metadata.source(_1.source_name).modules? }.size,
|
143
182
|
}
|
144
183
|
end,
|
145
184
|
pagination: pagination.to_h
|
@@ -161,6 +200,32 @@ module DiverDown
|
|
161
200
|
)
|
162
201
|
end
|
163
202
|
|
203
|
+
# GET /api/module_definition/:module_names.json
|
204
|
+
#
|
205
|
+
# @param bit_id [Integer]
|
206
|
+
# @param compound [Boolean]
|
207
|
+
# @param concentrate [Boolean]
|
208
|
+
# @param only_module [Boolean]
|
209
|
+
# @param modules [Array<String>]
|
210
|
+
def module_definition(compound, concentrate, only_module, modules)
|
211
|
+
definition = @store.combined_definition
|
212
|
+
|
213
|
+
# Filter all sources and dependencies by modules if match_modules is given
|
214
|
+
resolved_definition = DiverDown::Web::ModuleSourcesFilter.new(@metadata).filter(definition, modules:)
|
215
|
+
|
216
|
+
# Resolve source aliases
|
217
|
+
resolved_definition = @source_alias_resolver.resolve(resolved_definition)
|
218
|
+
|
219
|
+
render_combined_definition(
|
220
|
+
(1..@store.size).to_a,
|
221
|
+
resolved_definition,
|
222
|
+
modules,
|
223
|
+
compound:,
|
224
|
+
concentrate:,
|
225
|
+
only_module:
|
226
|
+
)
|
227
|
+
end
|
228
|
+
|
164
229
|
# GET /api/definitions/:bit_id.json
|
165
230
|
#
|
166
231
|
# @param bit_id [Integer]
|
@@ -187,22 +252,16 @@ module DiverDown
|
|
187
252
|
end
|
188
253
|
|
189
254
|
if definition
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
memo: @module_store.get_memo(_1.source_name),
|
201
|
-
modules: @module_store.get_modules(_1.source_name).map do |module_name|
|
202
|
-
{ module_name: }
|
203
|
-
end,
|
204
|
-
}
|
205
|
-
end
|
255
|
+
# Resolve source aliases
|
256
|
+
resolved_definition = @source_alias_resolver.resolve(definition)
|
257
|
+
|
258
|
+
render_combined_definition(
|
259
|
+
valid_ids,
|
260
|
+
resolved_definition,
|
261
|
+
titles,
|
262
|
+
compound:,
|
263
|
+
concentrate:,
|
264
|
+
only_module:
|
206
265
|
)
|
207
266
|
else
|
208
267
|
not_found
|
@@ -249,12 +308,13 @@ module DiverDown
|
|
249
308
|
[]
|
250
309
|
else
|
251
310
|
source = DiverDown::Definition::Source.combine(*found_sources)
|
252
|
-
@
|
311
|
+
@metadata.source(source.source_name).modules
|
253
312
|
end
|
254
313
|
|
255
314
|
json(
|
256
315
|
source_name:,
|
257
|
-
|
316
|
+
resolved_alias: @metadata.source_alias.resolve_alias(source_name),
|
317
|
+
memo: @metadata.source(source_name).memo,
|
258
318
|
modules: module_names.map do
|
259
319
|
{ module_name: _1 }
|
260
320
|
end,
|
@@ -291,8 +351,8 @@ module DiverDown
|
|
291
351
|
end
|
292
352
|
|
293
353
|
if found_source
|
294
|
-
@
|
295
|
-
@
|
354
|
+
@metadata.source(source_name).modules = modules
|
355
|
+
@metadata.flush
|
296
356
|
|
297
357
|
json({})
|
298
358
|
else
|
@@ -312,8 +372,8 @@ module DiverDown
|
|
312
372
|
end
|
313
373
|
|
314
374
|
if found_source
|
315
|
-
@
|
316
|
-
@
|
375
|
+
@metadata.source(source_name).memo = memo
|
376
|
+
@metadata.flush
|
317
377
|
|
318
378
|
json({})
|
319
379
|
else
|
@@ -370,8 +430,33 @@ module DiverDown
|
|
370
430
|
end
|
371
431
|
end
|
372
432
|
|
373
|
-
def json(data)
|
374
|
-
[
|
433
|
+
def json(data, status = 200)
|
434
|
+
[status, { 'content-type' => 'application/json' }, [data.to_json]]
|
435
|
+
end
|
436
|
+
|
437
|
+
def json_error(message, status = 422)
|
438
|
+
json({ message: }, status)
|
439
|
+
end
|
440
|
+
|
441
|
+
def render_combined_definition(ids, definition, titles, compound:, concentrate:, only_module:)
|
442
|
+
definition_to_dot = DiverDown::Web::DefinitionToDot.new(definition, @metadata, compound:, concentrate:, only_module:)
|
443
|
+
|
444
|
+
json(
|
445
|
+
titles:,
|
446
|
+
bit_id: DiverDown::Web::BitId.ids_to_bit_id(ids).to_s,
|
447
|
+
dot: definition_to_dot.to_s,
|
448
|
+
dot_metadata: definition_to_dot.dot_metadata,
|
449
|
+
sources: definition.sources.map do
|
450
|
+
{
|
451
|
+
source_name: _1.source_name,
|
452
|
+
resolved_alias: @metadata.source_alias.resolve_alias(_1.source_name),
|
453
|
+
memo: @metadata.source(_1.source_name).memo,
|
454
|
+
modules: @metadata.source(_1.source_name).modules.map do |module_name|
|
455
|
+
{ module_name: }
|
456
|
+
end,
|
457
|
+
}
|
458
|
+
end
|
459
|
+
)
|
375
460
|
end
|
376
461
|
end
|
377
462
|
end
|
@@ -5,12 +5,11 @@ module DiverDown
|
|
5
5
|
class DefinitionStore
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
attr_reader :bit_id
|
9
|
-
|
10
8
|
def initialize
|
11
9
|
# Hash{ Integer(unique bit flag) => DiverDown::Definition }
|
12
10
|
@definitions = []
|
13
11
|
@definition_group_store = Hash.new { |h, k| h[k] = [] }
|
12
|
+
@combined_definition = nil
|
14
13
|
end
|
15
14
|
|
16
15
|
# @param id [Integer]
|
@@ -31,14 +30,33 @@ module DiverDown
|
|
31
30
|
raise(ArgumentError, 'definition already set') if _1.store_id
|
32
31
|
|
33
32
|
_1.store_id = @definitions.size + 1
|
33
|
+
_1.freeze
|
34
34
|
|
35
35
|
@definitions.push(_1)
|
36
36
|
@definition_group_store[_1.definition_group] << _1
|
37
37
|
|
38
|
+
# Reset combined_definition
|
39
|
+
@combined_definition = nil
|
40
|
+
|
38
41
|
_1.store_id
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
45
|
+
# @return [DiverDown::Definition]
|
46
|
+
def combined_definition
|
47
|
+
if @combined_definition.nil?
|
48
|
+
@combined_definition = DiverDown::Definition.combine(
|
49
|
+
definition_group: nil,
|
50
|
+
title: 'All Definitions',
|
51
|
+
definitions: @definitions
|
52
|
+
)
|
53
|
+
|
54
|
+
@combined_definition.freeze
|
55
|
+
end
|
56
|
+
|
57
|
+
@combined_definition
|
58
|
+
end
|
59
|
+
|
42
60
|
# @return [Array<String, nil>]
|
43
61
|
def definition_groups
|
44
62
|
keys = @definition_group_store.keys
|