diver_down 0.0.1.alpha13 → 0.0.1.alpha14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cb1048dc3dd78965342bb1747ddbf2cc0c84c7c62dbb73fe22a719e64844ffd
4
- data.tar.gz: f1137e211bebc58a87a2624916bca7db8d9e2eb29c67bdd6c554b8b3d306f1cd
3
+ metadata.gz: 12f54ddda5108f877d6e1510710b5a397dfc92db94c21f6521739b5032e4351f
4
+ data.tar.gz: 4c3c4b1063fd4da506077a8f9908a9f621336ffed58e0f5fc8b4c9c5b54cbd15
5
5
  SHA512:
6
- metadata.gz: d90b43e78ed7971c7404d703c0ba7c5965b71cf463ca94fd3a5809a0f0070fd3f8771b5f3f38d5a1ca368e5b5a4381b1a3377b5f3e421d81ac9c550c2066e703
7
- data.tar.gz: 520e8c6e07d5c6f9815f8a71a5f7ce1b08796c358d6792f4952b7c80b636264fcbf28b3d0cf579ecfc7ed4586292f8b0216ff5fff5415b6100281c218eb31a40
6
+ metadata.gz: 476bee3370a190cb94adb215abe7c58deb8c0dac475fca258c9e673d09471c477f5ba7826ba2575524c0f80c1f5454236bb71fd244c8306d02d75ad7766e85b9
7
+ data.tar.gz: 2e155be624f952d2b0e69d8d9a5ec549053e7f2ddfa469c2ce998777421cab30a73a423a2ecba5264f1fe7e603c4186413a801dfcbe49e82ca39d8bad7ec4531
data/README.md CHANGED
@@ -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
- - `--module-store-path` 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.
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 --module-store-path tmp/module_store.yml
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 DIVER_DOWN_MODULE_STORE=/path/to/module_store.yml bundle exec puma
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 --module-store /path/to/module_store.yml
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('--module-store PATH', 'Path to the module store') do |path|
27
- options[:module_store] = path
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
- module_store: DiverDown::Web::ModuleStore.new(options[:module_store] || Tempfile.new(['module_store', '.yaml']))
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
@@ -78,6 +78,12 @@ module DiverDown
78
78
  def inspect
79
79
  %(#<#{self.class} #{human_method_name} paths=#{paths.inspect}>")
80
80
  end
81
+
82
+ # @return [void]
83
+ def freeze
84
+ super
85
+ @paths.freeze
86
+ end
81
87
  end
82
88
  end
83
89
  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
@@ -103,5 +103,13 @@ module DiverDown
103
103
  [self.class, definition_group, title, sources].hash
104
104
  end
105
105
  end
106
+
107
+ # @return [void]
108
+ def freeze
109
+ super
110
+
111
+ @source_map.transform_values(&:freeze)
112
+ @source_map.freeze
113
+ end
106
114
  end
107
115
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiverDown
4
- VERSION = '0.0.1.alpha13'
4
+ VERSION = '0.0.1.alpha14'
5
5
  end
@@ -13,14 +13,50 @@ module DiverDown
13
13
  )
14
14
 
15
15
  # @param store [DiverDown::Definition::Store]
16
- # @param module_store [DiverDown::Web::ModuleStore]
16
+ # @param metadata [DiverDown::Web::Metadata]
17
17
  # @param request [Rack::Request]
18
- def initialize(store:, module_store:, request:)
18
+ def initialize(store:, metadata:, request:)
19
19
  @store = store
20
- @module_store = module_store
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 { @module_store.classified?(_1) }
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
- memo: @module_store.get_memo(source_name),
43
- modules: @module_store.get_modules(source_name).map do |module_name|
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 = @module_store.get_modules(source.source_name)
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 = @module_store.get_modules(source.source_name)
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: @module_store.get_memo(source_name),
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 { @module_store.classified?(_1.source_name) }.size,
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
- definition_to_dot = DiverDown::Web::DefinitionToDot.new(definition, @module_store, compound:, concentrate:, only_module:)
191
-
192
- json(
193
- titles:,
194
- bit_id: DiverDown::Web::BitId.ids_to_bit_id(valid_ids).to_s,
195
- dot: definition_to_dot.to_s,
196
- dot_metadata: definition_to_dot.metadata,
197
- sources: definition.sources.map do
198
- {
199
- source_name: _1.source_name,
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
- @module_store.get_modules(source.source_name)
311
+ @metadata.source(source.source_name).modules
253
312
  end
254
313
 
255
314
  json(
256
315
  source_name:,
257
- memo: @module_store.get_memo(source_name),
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
- @module_store.set_modules(source_name, modules)
295
- @module_store.flush
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
- @module_store.set_memo(source_name, memo)
316
- @module_store.flush
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
- [200, { 'content-type' => 'application/json' }, [data.to_json]]
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