decode 0.20.2 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/decode/index.rb +33 -9
- data/lib/decode/definition.rb +9 -0
- data/lib/decode/index.rb +1 -1
- data/lib/decode/language/ruby/definition.rb +10 -2
- data/lib/decode/language/ruby/parser.rb +49 -6
- data/lib/decode/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 745a2d58b25edbffce374091e5ea4fb81eb9473d2e0de28353e96835a1bfb24b
|
4
|
+
data.tar.gz: e7b5b0ba014dad20f2df889d981a3431920f90908381dbdd697610a0a036171f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1125299d2e5f2ff38f1192622ff28f9d9da3228d1f2c2f493b7aba5920f767962e81e9a538efa6c6387e87e79ad3f276d95cd9c68edb607c8e772978b1c3209a
|
7
|
+
data.tar.gz: 1f87468afd6db7116947c82e2ca16ac111e2faa4ace6b945f83b87bcf47aa9743b0e830c2ea26d1024909d5daf437f00773381de8cf86a9c2acf82f3cfa8db37
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/bake/decode/index.rb
CHANGED
@@ -14,20 +14,44 @@ def coverage(root)
|
|
14
14
|
index = Decode::Index.new
|
15
15
|
index.update(paths)
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
missing = []
|
18
|
+
public_count = 0
|
19
|
+
documented_count = 0
|
19
20
|
|
20
|
-
index.
|
21
|
-
|
21
|
+
index.trie.traverse do |path, node, descend|
|
22
|
+
public_definition = node.values.nil?
|
23
|
+
|
24
|
+
node.values&.each do |definition|
|
25
|
+
if definition.public?
|
26
|
+
public_count += 1
|
27
|
+
level = path.size
|
28
|
+
|
29
|
+
if definition.comments.nil?
|
30
|
+
missing << definition.qualified_name
|
31
|
+
else
|
32
|
+
documented_count += 1
|
33
|
+
end
|
34
|
+
|
35
|
+
public_definition = true
|
36
|
+
end
|
37
|
+
end
|
22
38
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
$stderr.puts "#{name}"
|
39
|
+
# Don't descend into non-public definitions:
|
40
|
+
if public_definition
|
41
|
+
descend.call
|
27
42
|
end
|
28
43
|
end
|
29
44
|
|
30
|
-
$stderr.puts "#{
|
45
|
+
$stderr.puts "#{documented_count} definitions have documentation, out of #{public_count} public definitions."
|
46
|
+
|
47
|
+
if documented_count < public_count
|
48
|
+
$stderr.puts nil, "Missing documentation for:"
|
49
|
+
missing.each do |name|
|
50
|
+
$stderr.puts "- #{name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
raise RuntimeError, "Insufficient documentation!"
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
# Process the given source root and report on symbols.
|
data/lib/decode/definition.rb
CHANGED
@@ -48,6 +48,15 @@ module Decode
|
|
48
48
|
# @attribute [Array(String)]
|
49
49
|
attr :comments
|
50
50
|
|
51
|
+
# Whether the definition is considered part of the public interface.
|
52
|
+
#
|
53
|
+
# This is used to determine whether the definition should be documented for coverage purposes.
|
54
|
+
#
|
55
|
+
# @returns [Boolean]
|
56
|
+
def public?
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
51
60
|
# The qualified name is an absolute name which includes any and all namespacing.
|
52
61
|
# @returns [String]
|
53
62
|
def qualified_name
|
data/lib/decode/index.rb
CHANGED
@@ -11,19 +11,27 @@ module Decode
|
|
11
11
|
# A Ruby-specific definition.
|
12
12
|
class Definition < Decode::Definition
|
13
13
|
# Initialize the definition from the syntax tree node.
|
14
|
-
def initialize(node, *arguments, **options)
|
14
|
+
def initialize(node, *arguments, visibility: nil, **options)
|
15
15
|
super(*arguments, **options)
|
16
16
|
|
17
17
|
@node = node
|
18
|
+
@visibility = visibility
|
18
19
|
end
|
19
20
|
|
20
21
|
def nested_name
|
21
22
|
"\##{@name}"
|
22
23
|
end
|
23
24
|
|
24
|
-
# The parser syntax tree node.
|
25
|
+
# @attribute [Parser::AST::Node] The parser syntax tree node.
|
25
26
|
attr :node
|
26
27
|
|
28
|
+
# @attribute [Symbol] The visibility of the definition.
|
29
|
+
attr_accessor :visibility
|
30
|
+
|
31
|
+
def public?
|
32
|
+
@visibility == :public
|
33
|
+
end
|
34
|
+
|
27
35
|
def multiline?
|
28
36
|
@node.location.line != @node.location.last_line
|
29
37
|
end
|
@@ -25,6 +25,17 @@ module Decode
|
|
25
25
|
class Parser
|
26
26
|
def initialize(language)
|
27
27
|
@language = language
|
28
|
+
|
29
|
+
@visibility = :public
|
30
|
+
@definitions = Hash.new.compare_by_identity
|
31
|
+
end
|
32
|
+
|
33
|
+
private def assign_definition(parent, definition)
|
34
|
+
(@definitions[parent] ||= {})[definition.name] = definition
|
35
|
+
end
|
36
|
+
|
37
|
+
private def lookup_definition(parent, name)
|
38
|
+
(@definitions[parent] ||= {})[name]
|
28
39
|
end
|
29
40
|
|
30
41
|
# Parse the given source object, can be a string or a Source instance.
|
@@ -71,6 +82,14 @@ module Decode
|
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
85
|
+
def with_visibility(visibility = :public, &block)
|
86
|
+
saved_visibility = @visibility
|
87
|
+
@visibility = visibility
|
88
|
+
yield
|
89
|
+
ensure
|
90
|
+
@visibility = saved_visibility
|
91
|
+
end
|
92
|
+
|
74
93
|
# Walk over the syntax tree and extract relevant definitions with their associated comments.
|
75
94
|
def walk_definitions(node, comments, parent = nil, &block)
|
76
95
|
case node.type
|
@@ -82,29 +101,37 @@ module Decode
|
|
82
101
|
language: @language
|
83
102
|
)
|
84
103
|
|
104
|
+
assign_definition(parent, definition)
|
105
|
+
|
85
106
|
yield definition
|
86
107
|
|
87
108
|
if children = node.children[1]
|
88
|
-
|
109
|
+
with_visibility do
|
110
|
+
walk_definitions(children, comments, definition, &block)
|
111
|
+
end
|
89
112
|
end
|
90
113
|
when :class
|
91
114
|
definition = Class.new(
|
92
115
|
node, nested_name_for(node.children[0]),
|
93
116
|
comments: extract_comments_for(node, comments),
|
94
|
-
parent: parent, language: @language
|
117
|
+
parent: parent, language: @language, visibility: :public
|
95
118
|
)
|
96
119
|
|
120
|
+
assign_definition(parent, definition)
|
121
|
+
|
97
122
|
yield definition
|
98
123
|
|
99
124
|
if children = node.children[2]
|
100
|
-
|
125
|
+
with_visibility do
|
126
|
+
walk_definitions(children, comments, definition, &block)
|
127
|
+
end
|
101
128
|
end
|
102
129
|
when :sclass
|
103
130
|
if name = singleton_name_for(node.children[0])
|
104
131
|
definition = Singleton.new(
|
105
132
|
node, name,
|
106
133
|
comments: extract_comments_for(node, comments),
|
107
|
-
parent: parent, language: @language
|
134
|
+
parent: parent, language: @language, visibility: :public
|
108
135
|
)
|
109
136
|
|
110
137
|
yield definition
|
@@ -117,7 +144,7 @@ module Decode
|
|
117
144
|
definition = Method.new(
|
118
145
|
node, node.children[0],
|
119
146
|
comments: extract_comments_for(node, comments),
|
120
|
-
parent: parent, language: @language
|
147
|
+
parent: parent, language: @language, visibility: @visibility
|
121
148
|
)
|
122
149
|
|
123
150
|
yield definition
|
@@ -128,7 +155,7 @@ module Decode
|
|
128
155
|
node, node.children[1],
|
129
156
|
comments: extracted_comments,
|
130
157
|
parent: scope_for(extracted_comments, parent, &block),
|
131
|
-
language: @language
|
158
|
+
language: @language, visibility: @visibility
|
132
159
|
)
|
133
160
|
|
134
161
|
yield definition
|
@@ -144,6 +171,14 @@ module Decode
|
|
144
171
|
name = node.children[1]
|
145
172
|
|
146
173
|
case name
|
174
|
+
when :public, :protected, :private
|
175
|
+
@visibility = name
|
176
|
+
when :private_constant
|
177
|
+
constant_names_for(node.children[2..]) do |name|
|
178
|
+
if definition = lookup_definition(parent, name)
|
179
|
+
definition.visibility = :private
|
180
|
+
end
|
181
|
+
end
|
147
182
|
when :attr, :attr_reader, :attr_writer, :attr_accessor
|
148
183
|
definition = Attribute.new(
|
149
184
|
node, name_for(node.children[2]),
|
@@ -263,6 +298,14 @@ module Decode
|
|
263
298
|
return parent
|
264
299
|
end
|
265
300
|
|
301
|
+
def constant_names_for(children)
|
302
|
+
children.each do |node|
|
303
|
+
if node.type == :sym
|
304
|
+
yield node.children[0]
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
266
309
|
# Extract segments from the given input file.
|
267
310
|
def segments_for(source, &block)
|
268
311
|
top, comments = self.parse_source(source)
|
data/lib/decode/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date:
|
40
|
+
date: 2024-07-12 00:00:00.000000000 Z
|
41
41
|
dependencies:
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: parser
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
- !ruby/object:Gem::Version
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
|
-
rubygems_version: 3.
|
128
|
+
rubygems_version: 3.5.9
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Code analysis for documentation generation.
|
metadata.gz.sig
CHANGED
Binary file
|