diver_down 0.0.1.alpha8 → 0.0.1.alpha10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b6dec73d4653351d9d352e2576d572e3e16617d4b93b7fac88d1f92346f0d6d
4
- data.tar.gz: '0429bc45357cdf12327e0960b379d65df8ffe6d345c23b99600b3ab9e9d02f98'
3
+ metadata.gz: 45734000dad7ab44ca75037957b39dc6caae34d1189864f563ec251453972db8
4
+ data.tar.gz: bf21e0f1faeaa051f6fc4e001ff0544570994fc98d8cc75da92c8fd5f6e5d294
5
5
  SHA512:
6
- metadata.gz: 012d06bc87393013c42a7b6033507845c7efe36f654058a8afcde1e7b2f229d6b33e45e66e4465ac770c07b69a500adec6ef80e8da98c9ea2414f40f79a8ebc4
7
- data.tar.gz: 391c6a56bc9440b60b59eab6a05dfca33095d41a4c1ed7353661ff387f4f227c80865504c51e961c5d512e6cd2caec4d7147547b3ab7dcf54cd7f4d5f250d056
6
+ metadata.gz: 3060ddaba43ef6d91c01e9eb5b9ede908a61629e563d2dfef6b2775a59843cd3cd4e34c0505320ffc035e04459dc00744cf0dc58f8302de812a7b15d2b6b357c
7
+ data.tar.gz: bb258e2b3e308848e9debee4acd34930dbe375bc07ec639daeac97d24ff514f4e03a8f3b2cee8717ffb29d10b3600a97a645a9104b3481b4153c2f8ab0ce7ad9
@@ -46,6 +46,10 @@ module DiverDown
46
46
  next if TracePoint == tp.defined_class
47
47
 
48
48
  case tp.event
49
+ when :b_call
50
+ call_stack.push
51
+ when :b_return
52
+ call_stack.pop
49
53
  when :call, :c_call
50
54
  # puts "#{tp.method_id} #{tp.path}:#{tp.lineno}"
51
55
  if call_stack.ignored?
@@ -3,9 +3,18 @@
3
3
  module DiverDown
4
4
  module Trace
5
5
  class Tracer
6
+ DEFAULT_TRACE_EVENTS = %i[
7
+ call
8
+ return
9
+ c_call
10
+ c_return
11
+ b_call
12
+ b_return
13
+ ].freeze
14
+
6
15
  # @return [Array<Symbol>]
7
16
  def self.trace_events
8
- @trace_events || %i[call c_call return c_return]
17
+ @trace_events || DEFAULT_TRACE_EVENTS
9
18
  end
10
19
 
11
20
  # @param events [Array<Symbol>]
@@ -11,16 +11,12 @@ module DiverDown
11
11
  require 'diver_down/trace/redefine_ruby_methods'
12
12
  require 'diver_down/trace/ignored_method_ids'
13
13
 
14
- @trace_events = %i[
15
- call c_call return c_return
16
- ]
17
-
18
14
  # Trace only Ruby-implemented methods because tracing C-implemented methods is very slow
19
15
  # Override Ruby only with the minimal set of methods needed to trace dependencies.
20
16
  #
21
17
  # @return [void]
22
18
  def self.trace_only_ruby_world!(map = DiverDown::Trace::RedefineRubyMethods::DEFAULT_METHODS)
23
- DiverDown::Trace::Tracer.trace_events = %i[call return]
19
+ DiverDown::Trace::Tracer.trace_events = DiverDown::Trace::Tracer::DEFAULT_TRACE_EVENTS - %i[c_call c_return]
24
20
  DiverDown::Trace::RedefineRubyMethods.redefine_c_methods(map)
25
21
  end
26
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiverDown
4
- VERSION = '0.0.1.alpha8'
4
+ VERSION = '0.0.1.alpha10'
5
5
  end
@@ -33,12 +33,19 @@ module DiverDown
33
33
  end
34
34
  # rubocop:enable Style/HashEachMethods
35
35
 
36
+ classified_sources_count = source_names.count { @module_store.classified?(_1) }
37
+
36
38
  json(
37
39
  sources: source_names.sort.map do |source_name|
38
40
  {
39
41
  source_name:,
42
+ memo: @module_store.get_memo(source_name),
43
+ modules: @module_store.get_modules(source_name).map do |module_name|
44
+ { module_name: }
45
+ end,
40
46
  }
41
- end
47
+ end,
48
+ classified_sources_count:
42
49
  )
43
50
  end
44
51
 
@@ -50,7 +57,7 @@ module DiverDown
50
57
  # rubocop:disable Style/HashEachMethods
51
58
  @store.each do |_, definition|
52
59
  definition.sources.each do |source|
53
- modules = @module_store.get(source.source_name)
60
+ modules = @module_store.get_modules(source.source_name)
54
61
  module_set.add(modules) unless modules.empty?
55
62
  end
56
63
  end
@@ -77,7 +84,7 @@ module DiverDown
77
84
  # rubocop:disable Style/HashEachMethods
78
85
  @store.each do |_, definition|
79
86
  definition.sources.each do |source|
80
- source_module_names = @module_store.get(source.source_name)
87
+ source_module_names = @module_store.get_modules(source.source_name)
81
88
 
82
89
  next unless source_module_names[0..module_names.size - 1] == module_names
83
90
 
@@ -102,6 +109,7 @@ module DiverDown
102
109
  sources: source_names.sort.map do |source_name|
103
110
  {
104
111
  source_name:,
112
+ memo: @module_store.get_memo(source_name),
105
113
  }
106
114
  end,
107
115
  related_definitions: related_definitions.map do |definition|
@@ -131,7 +139,7 @@ module DiverDown
131
139
  definition_group: definition.definition_group,
132
140
  title: definition.title,
133
141
  sources_count: definition.sources.size,
134
- unclassified_sources_count: definition.sources.reject { @module_store.include?(_1.source_name) }.size,
142
+ unclassified_sources_count: definition.sources.reject { @module_store.classified?(_1.source_name) }.size,
135
143
  }
136
144
  end,
137
145
  pagination: pagination.to_h
@@ -189,7 +197,8 @@ module DiverDown
189
197
  sources: definition.sources.map do
190
198
  {
191
199
  source_name: _1.source_name,
192
- modules: @module_store.get(_1.source_name).map do |module_name|
200
+ memo: @module_store.get_memo(_1.source_name),
201
+ modules: @module_store.get_modules(_1.source_name).map do |module_name|
193
202
  { module_name: }
194
203
  end,
195
204
  }
@@ -240,11 +249,12 @@ module DiverDown
240
249
  []
241
250
  else
242
251
  source = DiverDown::Definition::Source.combine(*found_sources)
243
- @module_store.get(source.source_name)
252
+ @module_store.get_modules(source.source_name)
244
253
  end
245
254
 
246
255
  json(
247
256
  source_name:,
257
+ memo: @module_store.get_memo(source_name),
248
258
  modules: module_names.map do
249
259
  { module_name: _1 }
250
260
  end,
@@ -281,7 +291,28 @@ module DiverDown
281
291
  end
282
292
 
283
293
  if found_source
284
- @module_store.set(source_name, modules)
294
+ @module_store.set_modules(source_name, modules)
295
+ @module_store.flush
296
+
297
+ json({})
298
+ else
299
+ not_found
300
+ end
301
+ end
302
+
303
+ # POST /api/sources/:source_name/memo.json
304
+ #
305
+ # @param source_name [String]
306
+ # @param memo [String]
307
+ def set_memo(source_name, memo)
308
+ found_source = @store.any? do |_, definition|
309
+ definition.sources.any? do |source|
310
+ source.source_name == source_name
311
+ end
312
+ end
313
+
314
+ if found_source
315
+ @module_store.set_memo(source_name, memo)
285
316
  @module_store.flush
286
317
 
287
318
  json({})
@@ -31,7 +31,7 @@ module DiverDown
31
31
  private
32
32
 
33
33
  def source_to_h
34
- modules = module_store.get(data.source_name).map do
34
+ modules = module_store.get_modules(data.source_name).map do
35
35
  {
36
36
  module_name: _1,
37
37
  }
@@ -41,6 +41,7 @@ module DiverDown
41
41
  id:,
42
42
  type: 'source',
43
43
  source_name: data.source_name,
44
+ memo: module_store.get_memo(data.source_name),
44
45
  modules:,
45
46
  }
46
47
  end
@@ -185,11 +186,11 @@ module DiverDown
185
186
  dependency_map = Hash.new { |h, k| h[k] = Hash.new { |hi, ki| hi[ki] = [] } }
186
187
 
187
188
  definition.sources.sort_by(&:source_name).each do |source|
188
- source_modules = module_store.get(source.source_name)
189
+ source_modules = module_store.get_modules(source.source_name)
189
190
  next if source_modules.empty?
190
191
 
191
192
  source.dependencies.each do |dependency|
192
- dependency_modules = module_store.get(dependency.source_name)
193
+ dependency_modules = module_store.get_modules(dependency.source_name)
193
194
  next if dependency_modules.empty?
194
195
 
195
196
  dependency_map[source_modules][dependency_modules].push(dependency)
@@ -268,7 +269,7 @@ module DiverDown
268
269
 
269
270
  def render_sources
270
271
  by_modules = definition.sources.group_by do |source|
271
- module_store.get(source.source_name)
272
+ module_store.get_modules(source.source_name)
272
273
  end
273
274
 
274
275
  # Remove duplicated prefix modules
@@ -326,8 +327,8 @@ module DiverDown
326
327
  def insert_dependencies(source)
327
328
  source.dependencies.each do
328
329
  attributes = {}
329
- ltail = module_label(*module_store.get(source.source_name))
330
- lhead = module_label(*module_store.get(_1.source_name))
330
+ ltail = module_label(*module_store.get_modules(source.source_name))
331
+ lhead = module_label(*module_store.get_modules(_1.source_name))
331
332
 
332
333
  if @compound && (ltail || lhead)
333
334
  # Rendering of dependencies between modules is done only once
@@ -6,6 +6,7 @@ module DiverDown
6
6
  class Web
7
7
  class ModuleStore
8
8
  BLANK_ARRAY = [].freeze
9
+ BLANK_MEMO = ''
9
10
  BLANK_RE = /\A\s*\z/
10
11
 
11
12
  private_constant(:BLANK_RE)
@@ -17,22 +18,42 @@ module DiverDown
17
18
 
18
19
  # @param source_name [String]
19
20
  # @param module_names [Array<String>]
20
- def set(source_name, module_names)
21
- @store[source_name] = module_names.dup.reject do
21
+ def set_modules(source_name, module_names)
22
+ source = (@store[source_name] ||= {})
23
+
24
+ source[:modules] = module_names.dup.reject do
22
25
  BLANK_RE.match?(_1)
23
26
  end.freeze
24
27
  end
25
28
 
26
29
  # @param source_name [String]
27
30
  # @return [Array<Module>]
28
- def get(source_name)
29
- @store[source_name] || BLANK_ARRAY
31
+ def get_modules(source_name)
32
+ return BLANK_ARRAY unless @store.key?(source_name)
33
+
34
+ @store[source_name][:modules] || BLANK_ARRAY
35
+ end
36
+
37
+ # @param source_name [String]
38
+ # @param memo [String]
39
+ # @return [void]
40
+ def set_memo(source_name, memo)
41
+ source = (@store[source_name] ||= {})
42
+ source[:memo] = memo.strip
43
+ end
44
+
45
+ # @param source_name [String]
46
+ # @return [String]
47
+ def get_memo(source_name)
48
+ return BLANK_MEMO unless @store.key?(source_name)
49
+
50
+ @store[source_name][:memo] || BLANK_MEMO
30
51
  end
31
52
 
32
53
  # @param source_name [String]
33
54
  # @return [Boolean]
34
- def include?(source_name)
35
- get(source_name).any?
55
+ def classified?(source_name)
56
+ get_modules(source_name).any?
36
57
  end
37
58
 
38
59
  # @return [Hash]
@@ -53,7 +53,7 @@ module DiverDown
53
53
  in ['GET', %r{\A/api/modules\.json\z}]
54
54
  action.modules
55
55
  in ['GET', %r{\A/api/modules/(?<module_names>.+)\.json\z}]
56
- module_names = Regexp.last_match[:module_names].split('/')
56
+ module_names = CGI.unescape(Regexp.last_match[:module_names]).split('/')
57
57
  action.module(module_names)
58
58
  in ['GET', %r{\A/api/definitions/(?<bit_id>\d+)\.json\z}]
59
59
  bit_id = Regexp.last_match[:bit_id].to_i
@@ -68,6 +68,10 @@ module DiverDown
68
68
  source = Regexp.last_match[:source]
69
69
  modules = request.params['modules'] || []
70
70
  action.set_modules(source, modules)
71
+ in ['POST', %r{\A/api/sources/(?<source>[^/]+)/memo.json\z}]
72
+ source = Regexp.last_match[:source]
73
+ memo = request.params['memo'] || ''
74
+ action.set_memo(source, memo)
71
75
  in ['GET', %r{\A/api/pid\.json\z}]
72
76
  action.pid
73
77
  in ['GET', %r{\A/api/initialization_status\.json\z}]