auto_type_doc 0.1.1
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 +7 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +132 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/auto_type_doc.gemspec +39 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/foo_test.rb +55 -0
- data/lib/auto_type_doc.rb +126 -0
- data/lib/auto_type_doc/argument.rb +38 -0
- data/lib/auto_type_doc/method_info.rb +71 -0
- data/lib/auto_type_doc/version.rb +3 -0
- data/type_doc/types.json +99 -0
- metadata +146 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 78f3bb6835356121a3179d8fa8220e2718ec85c5
|
|
4
|
+
data.tar.gz: f80b263c640383b2d1b2f5c2948abc601aaf31ae
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 99e9358fee430832c00a4f0fe4d5774685487fce3fab55f439e9f8f584389acf4185caf80267add1fc4f184083ddeebcaee4dd08725ab378b7a46c24674bb5dd
|
|
7
|
+
data.tar.gz: d6e3f62879028b552c96640fe30dba19c8dc1dff23ef255d1e926f6af03a1bc12be10787e9c7a394d443f1929704ac5070d2e84528cb41babbf1bd667c13b496
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# https://github.com/bbatsov/rubocop/blob/master/config/default.yml
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
Include:
|
|
5
|
+
- Rakefile
|
|
6
|
+
TargetRubyVersion: 2.5
|
|
7
|
+
|
|
8
|
+
LineLength:
|
|
9
|
+
Max: 80
|
|
10
|
+
Exclude:
|
|
11
|
+
- test/**/**
|
|
12
|
+
|
|
13
|
+
Layout/ExtraSpacing:
|
|
14
|
+
Enabled: false
|
|
15
|
+
|
|
16
|
+
Layout/SpaceInsideStringInterpolation:
|
|
17
|
+
Enabled: false
|
|
18
|
+
|
|
19
|
+
Layout/EmptyLinesAroundBlockBody:
|
|
20
|
+
Enabled: false
|
|
21
|
+
|
|
22
|
+
Layout/EmptyLinesAroundClassBody:
|
|
23
|
+
Enabled: false
|
|
24
|
+
|
|
25
|
+
Layout/EmptyLinesAroundModuleBody:
|
|
26
|
+
Enabled: false
|
|
27
|
+
|
|
28
|
+
Layout/EmptyLineBetweenDefs:
|
|
29
|
+
NumberOfEmptyLines: [1, 2]
|
|
30
|
+
|
|
31
|
+
Layout/MultilineOperationIndentation:
|
|
32
|
+
EnforcedStyle: indented
|
|
33
|
+
|
|
34
|
+
Layout/AlignParameters:
|
|
35
|
+
EnforcedStyle: with_first_parameter
|
|
36
|
+
|
|
37
|
+
Layout/DotPosition:
|
|
38
|
+
Enabled: false
|
|
39
|
+
|
|
40
|
+
Style/PercentLiteralDelimiters:
|
|
41
|
+
Enabled: false
|
|
42
|
+
|
|
43
|
+
Style/StringLiterals:
|
|
44
|
+
Enabled: false
|
|
45
|
+
|
|
46
|
+
Style/StringLiteralsInInterpolation:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
Style/SingleLineBlockParams:
|
|
50
|
+
Enabled: false
|
|
51
|
+
|
|
52
|
+
Style/TrivialAccessors:
|
|
53
|
+
AllowPredicates: true
|
|
54
|
+
|
|
55
|
+
Style/Semicolon:
|
|
56
|
+
AllowAsExpressionSeparator: true
|
|
57
|
+
|
|
58
|
+
Style/PerlBackrefs:
|
|
59
|
+
Enabled: false
|
|
60
|
+
|
|
61
|
+
Style/SingleLineMethods:
|
|
62
|
+
Enabled: false
|
|
63
|
+
|
|
64
|
+
Style/Documentation:
|
|
65
|
+
Enabled: false
|
|
66
|
+
|
|
67
|
+
Style/RegexpLiteral:
|
|
68
|
+
Enabled: false
|
|
69
|
+
|
|
70
|
+
Style/CommandLiteral:
|
|
71
|
+
Enabled: false
|
|
72
|
+
|
|
73
|
+
Style/FrozenStringLiteralComment:
|
|
74
|
+
Enabled: false
|
|
75
|
+
|
|
76
|
+
Style/FormatString:
|
|
77
|
+
Enabled: false
|
|
78
|
+
|
|
79
|
+
Style/AsciiComments:
|
|
80
|
+
Enabled: false
|
|
81
|
+
|
|
82
|
+
Style/SymbolProc:
|
|
83
|
+
AutoCorrect: false
|
|
84
|
+
|
|
85
|
+
Style/EmptyMethod:
|
|
86
|
+
Enabled: false
|
|
87
|
+
|
|
88
|
+
Style/MultilineTernaryOperator:
|
|
89
|
+
Enabled: false
|
|
90
|
+
|
|
91
|
+
Style/DoubleNegation:
|
|
92
|
+
Enabled: false
|
|
93
|
+
|
|
94
|
+
Metrics/ClassLength:
|
|
95
|
+
Enabled: false
|
|
96
|
+
|
|
97
|
+
Metrics/ModuleLength:
|
|
98
|
+
Enabled: false
|
|
99
|
+
|
|
100
|
+
Metrics/MethodLength:
|
|
101
|
+
Enabled: false
|
|
102
|
+
|
|
103
|
+
Metrics/CyclomaticComplexity:
|
|
104
|
+
Enabled: false
|
|
105
|
+
|
|
106
|
+
Metrics/PerceivedComplexity:
|
|
107
|
+
Enabled: false
|
|
108
|
+
|
|
109
|
+
Metrics/AbcSize:
|
|
110
|
+
Enabled: false
|
|
111
|
+
|
|
112
|
+
Metrics/ParameterLists:
|
|
113
|
+
CountKeywordArgs: false
|
|
114
|
+
|
|
115
|
+
Metrics/BlockLength:
|
|
116
|
+
Enabled: false
|
|
117
|
+
|
|
118
|
+
Naming/HeredocDelimiterNaming:
|
|
119
|
+
Enabled: false
|
|
120
|
+
|
|
121
|
+
Naming/PredicateName:
|
|
122
|
+
Enabled: false
|
|
123
|
+
|
|
124
|
+
Naming/MethodName:
|
|
125
|
+
Enabled: false
|
|
126
|
+
|
|
127
|
+
Performance/RedundantBlockCall:
|
|
128
|
+
Enabled: false
|
|
129
|
+
|
|
130
|
+
Lint/UnusedMethodArgument:
|
|
131
|
+
Enabled: true
|
|
132
|
+
AutoCorrect: false
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby-2.4.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
auto_type_doc (0.1.1)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
byebug (10.0.2)
|
|
10
|
+
coderay (1.1.2)
|
|
11
|
+
method_source (0.9.0)
|
|
12
|
+
minitest (5.11.3)
|
|
13
|
+
pry (0.11.3)
|
|
14
|
+
coderay (~> 1.1.0)
|
|
15
|
+
method_source (~> 0.9.0)
|
|
16
|
+
pry-byebug (3.6.0)
|
|
17
|
+
byebug (~> 10.0)
|
|
18
|
+
pry (~> 0.10)
|
|
19
|
+
pry-doc (0.13.4)
|
|
20
|
+
pry (~> 0.11)
|
|
21
|
+
yard (~> 0.9.11)
|
|
22
|
+
rake (10.5.0)
|
|
23
|
+
yard (0.9.12)
|
|
24
|
+
|
|
25
|
+
PLATFORMS
|
|
26
|
+
ruby
|
|
27
|
+
|
|
28
|
+
DEPENDENCIES
|
|
29
|
+
auto_type_doc!
|
|
30
|
+
bundler (~> 1.16)
|
|
31
|
+
minitest (~> 5.0)
|
|
32
|
+
pry
|
|
33
|
+
pry-byebug
|
|
34
|
+
pry-doc
|
|
35
|
+
rake (~> 10.0)
|
|
36
|
+
|
|
37
|
+
BUNDLED WITH
|
|
38
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Rathesan Iyadurai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# AutoTypeDoc
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
Generates type documentation (e.g. YARD tags) by collecting runtime information.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'auto_type_doc'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install auto_type_doc
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rathrio/auto_type_doc.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "auto_type_doc/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "auto_type_doc"
|
|
8
|
+
spec.version = AutoTypeDoc::VERSION
|
|
9
|
+
spec.authors = ["Rathesan Iyadurai"]
|
|
10
|
+
spec.email = ["rad.iyadurai@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Automatic type documentation powered by Ruby's runtime information}
|
|
13
|
+
spec.description = %q{}
|
|
14
|
+
spec.homepage = "https://github.com/rathrio/auto_type_doc"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
# if spec.respond_to?(:metadata)
|
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
|
21
|
+
# else
|
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
# "public gem pushes."
|
|
24
|
+
# end
|
|
25
|
+
|
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
|
28
|
+
end
|
|
29
|
+
spec.bindir = "exe"
|
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ["lib"]
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
|
36
|
+
spec.add_development_dependency "pry"
|
|
37
|
+
spec.add_development_dependency "pry-doc"
|
|
38
|
+
spec.add_development_dependency "pry-byebug"
|
|
39
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "auto_type_doc"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/foo_test.rb
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
EXECUTABLE_FILE = File.realpath(__FILE__)
|
|
4
|
+
$LOAD_PATH.unshift File.expand_path('../lib', EXECUTABLE_FILE)
|
|
5
|
+
require 'auto_type_doc'
|
|
6
|
+
|
|
7
|
+
AutoTypeDoc.enable
|
|
8
|
+
class Dog
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class Fish
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module M
|
|
15
|
+
def bite(animal)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module CM
|
|
20
|
+
def eat(food)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.info(*args)
|
|
24
|
+
"CHELLO THERE"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class Cat
|
|
29
|
+
class << self
|
|
30
|
+
def chabis=(some_value)
|
|
31
|
+
some_value = some_value.to_a
|
|
32
|
+
@chabis = some_value
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.foobar(num)
|
|
37
|
+
num + 4
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
include M
|
|
41
|
+
extend CM
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
Cat.chabis = Set.new
|
|
45
|
+
Cat.new.bite(Dog.new)
|
|
46
|
+
Cat.foobar 2
|
|
47
|
+
Cat.foobar 8.9
|
|
48
|
+
Cat.foobar 123.34
|
|
49
|
+
|
|
50
|
+
Cat.eat(Fish.new)
|
|
51
|
+
|
|
52
|
+
CM.info(1, 2)
|
|
53
|
+
|
|
54
|
+
AutoTypeDoc.disable
|
|
55
|
+
AutoTypeDoc.dump_json
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require "auto_type_doc/version"
|
|
2
|
+
require "auto_type_doc/argument"
|
|
3
|
+
require "auto_type_doc/method_info"
|
|
4
|
+
|
|
5
|
+
require 'irb'
|
|
6
|
+
require 'pry'
|
|
7
|
+
require 'json'
|
|
8
|
+
require 'set'
|
|
9
|
+
require 'fileutils'
|
|
10
|
+
|
|
11
|
+
module AutoTypeDoc
|
|
12
|
+
module_function
|
|
13
|
+
|
|
14
|
+
METHOD_BLACK_LIST = %r{
|
|
15
|
+
AutoTypeDoc
|
|
16
|
+
}x
|
|
17
|
+
|
|
18
|
+
LOCATION_BLACK_LIST = %r{
|
|
19
|
+
rubies/
|
|
20
|
+
|/gems/
|
|
21
|
+
|/spec/
|
|
22
|
+
|/test/
|
|
23
|
+
}x
|
|
24
|
+
|
|
25
|
+
Tracker = TracePoint.new(:call, :return) do |t|
|
|
26
|
+
begin
|
|
27
|
+
method = t.self.method(t.method_id)
|
|
28
|
+
rescue
|
|
29
|
+
next
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
source_location = method.source_location
|
|
33
|
+
next if source_location.nil?
|
|
34
|
+
|
|
35
|
+
source_path = source_location[0]
|
|
36
|
+
next if source_path =~ LOCATION_BLACK_LIST
|
|
37
|
+
next if method.to_s =~ METHOD_BLACK_LIST
|
|
38
|
+
next if method_name_with_owner(method).start_with?("#<")
|
|
39
|
+
|
|
40
|
+
case t.event
|
|
41
|
+
when :call
|
|
42
|
+
next if method.parameters.empty?
|
|
43
|
+
on_call(t, method: method)
|
|
44
|
+
when :return
|
|
45
|
+
on_return(t, method: method)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# @param method [Method]
|
|
50
|
+
# @return [String]
|
|
51
|
+
def method_name_with_owner(method)
|
|
52
|
+
method.to_s[/^#<Method:\s(.+)>$/, 1].sub(/^.+\((.+)\)/, '\1')
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def on_call(t, method:)
|
|
56
|
+
method_info = method_info(method)
|
|
57
|
+
|
|
58
|
+
method.parameters.each_with_index do |(kind, name), index|
|
|
59
|
+
begin
|
|
60
|
+
obj = t.binding.local_variable_get(name)
|
|
61
|
+
rescue
|
|
62
|
+
next
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
method_info.add_argument(
|
|
66
|
+
name: name,
|
|
67
|
+
type: type(obj),
|
|
68
|
+
kind: kind,
|
|
69
|
+
position: index
|
|
70
|
+
)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# @return [String]
|
|
75
|
+
def type(obj)
|
|
76
|
+
if obj.is_a?(Array) && obj.any?
|
|
77
|
+
return "#{obj.class}<#{type(obj.first)}>"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
if obj.equal?(true) || obj.equal?(false)
|
|
81
|
+
return "Boolean"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
obj.class
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def on_return(t, method:)
|
|
88
|
+
method_info = method_info(method)
|
|
89
|
+
obj = t.return_value
|
|
90
|
+
method_info.add_return_type(type(obj))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def method_info(method)
|
|
94
|
+
key = method_name_with_owner(method)
|
|
95
|
+
|
|
96
|
+
AutoTypeDoc.all_method_info[key] ||= MethodInfo.new(
|
|
97
|
+
source_location: method.source_location
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
AutoTypeDoc.all_method_info[key]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def all_method_info
|
|
104
|
+
@all_method_info ||= {}
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def enable
|
|
108
|
+
Tracker.enable
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def disable
|
|
112
|
+
Tracker.disable
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def doc_dir
|
|
116
|
+
'./type_doc'
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def dump_json
|
|
120
|
+
FileUtils.mkdir_p(doc_dir)
|
|
121
|
+
|
|
122
|
+
File.open("#{doc_dir}/types.json", 'w') do |f|
|
|
123
|
+
f.write(JSON.pretty_generate(all_method_info))
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module AutoTypeDoc
|
|
2
|
+
class Argument
|
|
3
|
+
attr_reader :name, :types, :kind, :position
|
|
4
|
+
|
|
5
|
+
def initialize(name:, kind:, position:)
|
|
6
|
+
@name = name.to_s
|
|
7
|
+
@kind = kind.to_s
|
|
8
|
+
@types = Hash.new(0)
|
|
9
|
+
@position = position
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def add_type(type)
|
|
13
|
+
type = type.to_s
|
|
14
|
+
types[type] += 1
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def ==(other)
|
|
18
|
+
name == other.name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def eql?(other)
|
|
22
|
+
self == other
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def hash
|
|
26
|
+
name.hash
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def to_h
|
|
30
|
+
{
|
|
31
|
+
name: name,
|
|
32
|
+
types: types,
|
|
33
|
+
kind: kind,
|
|
34
|
+
position: position
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module AutoTypeDoc
|
|
2
|
+
class MethodInfo
|
|
3
|
+
attr_accessor :arguments
|
|
4
|
+
attr_accessor :return_types
|
|
5
|
+
attr_accessor :source_location
|
|
6
|
+
|
|
7
|
+
def initialize(source_location:)
|
|
8
|
+
@source_location = source_location
|
|
9
|
+
@arguments = Set.new
|
|
10
|
+
@return_types = Hash.new(0)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def source_file
|
|
14
|
+
source_location[0]
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def source_line
|
|
18
|
+
source_location[1]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def argument(name)
|
|
22
|
+
arguments.find { |a| a.name == name.to_s }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_argument(name:, type:, kind:, position:)
|
|
26
|
+
if (a = argument(name))
|
|
27
|
+
a.add_type(type)
|
|
28
|
+
else
|
|
29
|
+
a = Argument.new(name: name, kind: kind, position: position)
|
|
30
|
+
a.add_type(type)
|
|
31
|
+
arguments << a
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def add_return_type(type)
|
|
36
|
+
return_types[type.to_s] += 1
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# @return [String]
|
|
40
|
+
def most_frequent_arg_type(arg_name)
|
|
41
|
+
most_frequent_type(argument(arg_name).types)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @return [String]
|
|
45
|
+
def most_frequent_return_type
|
|
46
|
+
most_frequent_type(return_types)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def to_h
|
|
50
|
+
h = {}
|
|
51
|
+
h[:arguments] = arguments.map(&:to_h) if arguments.any?
|
|
52
|
+
h.merge(
|
|
53
|
+
return_types: return_types,
|
|
54
|
+
source_location: {
|
|
55
|
+
path: source_file,
|
|
56
|
+
line: source_line
|
|
57
|
+
}
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_json(*args)
|
|
62
|
+
to_h.to_json(*args)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
|
|
67
|
+
def most_frequent_type(type_hash)
|
|
68
|
+
type_hash.max_by { |_, count| count }[0]
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
data/type_doc/types.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Cat.chabis=": {
|
|
3
|
+
"arguments": [
|
|
4
|
+
{
|
|
5
|
+
"name": "some_value",
|
|
6
|
+
"types": {
|
|
7
|
+
"Set": 1
|
|
8
|
+
},
|
|
9
|
+
"kind": "req",
|
|
10
|
+
"position": 0
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"return_types": {
|
|
14
|
+
"Array": 1
|
|
15
|
+
},
|
|
16
|
+
"source_location": {
|
|
17
|
+
"file": "foo_test.rb",
|
|
18
|
+
"line": 30
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"M#bite": {
|
|
22
|
+
"arguments": [
|
|
23
|
+
{
|
|
24
|
+
"name": "animal",
|
|
25
|
+
"types": {
|
|
26
|
+
"Dog": 1
|
|
27
|
+
},
|
|
28
|
+
"kind": "req",
|
|
29
|
+
"position": 0
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
"return_types": {
|
|
33
|
+
"NilClass": 1
|
|
34
|
+
},
|
|
35
|
+
"source_location": {
|
|
36
|
+
"file": "foo_test.rb",
|
|
37
|
+
"line": 15
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"Cat.foobar": {
|
|
41
|
+
"arguments": [
|
|
42
|
+
{
|
|
43
|
+
"name": "num",
|
|
44
|
+
"types": {
|
|
45
|
+
"Integer": 1,
|
|
46
|
+
"Float": 2
|
|
47
|
+
},
|
|
48
|
+
"kind": "req",
|
|
49
|
+
"position": 0
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"return_types": {
|
|
53
|
+
"Integer": 1,
|
|
54
|
+
"Float": 2
|
|
55
|
+
},
|
|
56
|
+
"source_location": {
|
|
57
|
+
"file": "foo_test.rb",
|
|
58
|
+
"line": 36
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"CM#eat": {
|
|
62
|
+
"arguments": [
|
|
63
|
+
{
|
|
64
|
+
"name": "food",
|
|
65
|
+
"types": {
|
|
66
|
+
"Fish": 1
|
|
67
|
+
},
|
|
68
|
+
"kind": "req",
|
|
69
|
+
"position": 0
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
"return_types": {
|
|
73
|
+
"NilClass": 1
|
|
74
|
+
},
|
|
75
|
+
"source_location": {
|
|
76
|
+
"file": "foo_test.rb",
|
|
77
|
+
"line": 20
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"CM.info": {
|
|
81
|
+
"arguments": [
|
|
82
|
+
{
|
|
83
|
+
"name": "args",
|
|
84
|
+
"types": {
|
|
85
|
+
"Array<Integer>": 1
|
|
86
|
+
},
|
|
87
|
+
"kind": "rest",
|
|
88
|
+
"position": 0
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
"return_types": {
|
|
92
|
+
"String": 1
|
|
93
|
+
},
|
|
94
|
+
"source_location": {
|
|
95
|
+
"file": "foo_test.rb",
|
|
96
|
+
"line": 23
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
metadata
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: auto_type_doc
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Rathesan Iyadurai
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: minitest
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '5.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '5.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: pry-doc
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: pry-byebug
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
description: ''
|
|
98
|
+
email:
|
|
99
|
+
- rad.iyadurai@gmail.com
|
|
100
|
+
executables: []
|
|
101
|
+
extensions: []
|
|
102
|
+
extra_rdoc_files: []
|
|
103
|
+
files:
|
|
104
|
+
- ".gitignore"
|
|
105
|
+
- ".rubocop.yml"
|
|
106
|
+
- ".ruby-version"
|
|
107
|
+
- ".travis.yml"
|
|
108
|
+
- Gemfile
|
|
109
|
+
- Gemfile.lock
|
|
110
|
+
- LICENSE.txt
|
|
111
|
+
- README.md
|
|
112
|
+
- Rakefile
|
|
113
|
+
- auto_type_doc.gemspec
|
|
114
|
+
- bin/console
|
|
115
|
+
- bin/setup
|
|
116
|
+
- foo_test.rb
|
|
117
|
+
- lib/auto_type_doc.rb
|
|
118
|
+
- lib/auto_type_doc/argument.rb
|
|
119
|
+
- lib/auto_type_doc/method_info.rb
|
|
120
|
+
- lib/auto_type_doc/version.rb
|
|
121
|
+
- type_doc/types.json
|
|
122
|
+
homepage: https://github.com/rathrio/auto_type_doc
|
|
123
|
+
licenses:
|
|
124
|
+
- MIT
|
|
125
|
+
metadata: {}
|
|
126
|
+
post_install_message:
|
|
127
|
+
rdoc_options: []
|
|
128
|
+
require_paths:
|
|
129
|
+
- lib
|
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
|
+
requirements:
|
|
132
|
+
- - ">="
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '0'
|
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
|
+
requirements:
|
|
137
|
+
- - ">="
|
|
138
|
+
- !ruby/object:Gem::Version
|
|
139
|
+
version: '0'
|
|
140
|
+
requirements: []
|
|
141
|
+
rubyforge_project:
|
|
142
|
+
rubygems_version: 2.6.14
|
|
143
|
+
signing_key:
|
|
144
|
+
specification_version: 4
|
|
145
|
+
summary: Automatic type documentation powered by Ruby's runtime information
|
|
146
|
+
test_files: []
|