decode 0.10.1 → 0.11.0

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: 550e3f090191dd16e7977c43c25124af8f491b723164b140abcda0d9a0cb697c
4
- data.tar.gz: 662df9a115c165cdf69bd5de2e1dbe2f89af968209a9202955dd37399ecadf3b
3
+ metadata.gz: 07f79e45df5df94f23f1f47cc1a25d750da2d23b35223fec16424cfcb29151b9
4
+ data.tar.gz: e95e753098856a90efa1c0c92abae58f7b47f8105549aa4fd40e8d6cda1b0e18
5
5
  SHA512:
6
- metadata.gz: cda2284be27c82918e3f9a7bb3e3c597ff5ef2f57c89d8d25eff14d65407ee3d379b7863688942de4186f026aee5ae35134bfb175d0cf0d1da4df80bc06b3355
7
- data.tar.gz: 28731d765443e79141d0f23b3543f8665ac69a7f52830ae3462540d7e64924cc9764e614fa9b7b25f274c7be9fc38a02024fb756d16bb5c53b095cf283292147
6
+ metadata.gz: '0538b3e5f1bc385726957c7ae3e1227706e007ffedf14b3d49794551804403d7f97762b070d6bccba75690dea05d366212826584c80dfada4617902f7a6f4f74'
7
+ data.tar.gz: 66bc9443f5615e2e64ab8d4bc294940642cc89f34f22914d9232099b0cff5d453c36a744aec024954c9f9d57582cd4a8d50588851abeee7de5d7ed811557b0e3
@@ -0,0 +1,27 @@
1
+
2
+ # Process the given source root and report on comment coverage.
3
+ # @param root [String] The root path to index.
4
+ def coverage(root)
5
+ require 'build/files/glob'
6
+ require 'decode/index'
7
+
8
+ paths = Build::Files::Path.expand(root).glob("**/*")
9
+
10
+ index = Decode::Index.new
11
+ index.update(paths)
12
+
13
+ total = 0
14
+ documented = 0
15
+
16
+ index.definitions.each do |name, definition|
17
+ total += 1
18
+
19
+ if comments = definition.comments
20
+ documented += 1
21
+ else
22
+ $stderr.puts "#{name}"
23
+ end
24
+ end
25
+
26
+ $stderr.puts "#{documented}/#{total} definitions have documentation."
27
+ end
data/lib/decode/index.rb CHANGED
@@ -52,14 +52,15 @@ module Decode
52
52
  # @param paths [Array(String)] The source file paths.
53
53
  def update(paths)
54
54
  paths.each do |path|
55
- source = Source.new(path)
56
- @sources[path] = Source.new(path)
57
-
58
- source.definitions do |symbol|
59
- # $stderr.puts "Adding #{symbol.qualified_name} to #{symbol.lexical_path.join(' -> ')}"
55
+ if source = Source.for?(path)
56
+ @sources[path] = source
60
57
 
61
- @definitions[symbol.qualified_name] = symbol
62
- @trie.insert(symbol.path, symbol)
58
+ source.definitions do |symbol|
59
+ # $stderr.puts "Adding #{symbol.qualified_name} to #{symbol.lexical_path.join(' -> ')}"
60
+
61
+ @definitions[symbol.qualified_name] = symbol
62
+ @trie.insert(symbol.path, symbol)
63
+ end
63
64
  end
64
65
  end
65
66
  end
@@ -24,21 +24,23 @@ module Decode
24
24
  # An Ruby-specific reference which can be resolved to zero or more definitions.
25
25
  class Reference
26
26
  # Initialize the reference.
27
- # @param value [String] The string value of the reference.
28
- def initialize(value)
29
- @value = value
27
+ # @param text [String] The text text of the reference.
28
+ def initialize(text)
29
+ @text = text
30
30
 
31
31
  @lexical_path = nil
32
32
  @path = nil
33
33
  end
34
34
 
35
+ attr :text
36
+
35
37
  # Whether the reference starts at the base of the lexical tree.
36
38
  def absolute?
37
- @value.start_with?('::')
39
+ @text.start_with?('::')
38
40
  end
39
41
 
40
42
  def lexical_path
41
- @lexical_path ||= @value.scan(/(::|\.|#|:)?([^:.#]+)/)
43
+ @lexical_path ||= @text.scan(/(::|\.|#|:)?([^:.#]+)/)
42
44
  end
43
45
 
44
46
  def best(definitions)
@@ -24,10 +24,23 @@ module Decode
24
24
  # Language specific parsers and definitions.
25
25
  module Language
26
26
  def self.detect(path)
27
- case File.extname(path)
28
- when '.rb', '.ru'
27
+ case path
28
+ when /\.(rb|ru)\z/
29
29
  return Language::Ruby
30
30
  end
31
31
  end
32
+
33
+ REFERENCE = /\A(?<language>\.[a-z]+)?\s+(?<text>.*?)\z/
34
+
35
+ # A language agnostic reference:
36
+ # e.g. `.rb MyModule::MyClass`
37
+ #
38
+ def self.reference(string, language = nil)
39
+ if match = REFERENCE.match(string)
40
+ language = self.detect(match[:language]) || language
41
+
42
+ return language.reference(match[:text])
43
+ end
44
+ end
32
45
  end
33
46
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Decode
22
- VERSION = "0.10.1"
22
+ VERSION = "0.11.0"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-07 00:00:00.000000000 Z
11
+ date: 2020-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -119,6 +119,7 @@ files:
119
119
  - ".gitignore"
120
120
  - ".rspec"
121
121
  - README.md
122
+ - bake/decode/index.rb
122
123
  - decode.gemspec
123
124
  - gems.rb
124
125
  - guides/extract-symbols/extract.rb