irbs 0.1.0 → 0.2.0
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 +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +3 -1
- data/Rakefile +4 -4
- data/Steepfile +1 -1
- data/example/app.rb +4 -0
- data/example/{irbs.rbs → isig.rbs} +4 -0
- data/example/typeprof.rbs +4 -0
- data/lib/irbs/cli.rb +6 -5
- data/lib/irbs/core.rb +7 -1
- data/lib/irbs/monkey_patch.rb +20 -0
- data/lib/irbs/rbs_generator.rb +3 -3
- data/lib/irbs/template.rb +3 -1
- data/lib/irbs/version.rb +1 -1
- data/lib/irbs.rb +1 -0
- data/{isig/irbs.rbs → sig/isig.rbs} +6 -2
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9913638753b516454d942c3ac25e0a00a81e955c0d66535dab01afbb19a63d37
|
4
|
+
data.tar.gz: afb1d1f24bd72d41d5a7b6df29285e9dcb040809390b4d4ace4bbddd0b646bf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde271cafa4b35f8d9c35874b82bbe4c4b16dfd01540f57f50277bb615f68c4b61f1e57d974e3b309b2157dd1f348cc59b550f38633062e534525887c458bcd7
|
7
|
+
data.tar.gz: 583a39520e37c9eff50c327a6aaf5c6c534329ef7425505ae1647b19bd6c3d12ddc7c46287aaa5f8c10fdd3131cf89f78c20bfbccabab98b2ff3249c2053c8e0
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,8 @@ module App
|
|
26
26
|
arg.to_s
|
27
27
|
end
|
28
28
|
|
29
|
+
private
|
30
|
+
|
29
31
|
# @sig (String) -> Integer
|
30
32
|
def some_private_method(arg)
|
31
33
|
arg.to_i
|
@@ -48,7 +50,7 @@ end
|
|
48
50
|
See example task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`exmaple/`](https://github.com/diaphragm/irbs/tree/master/example) for more examples.
|
49
51
|
|
50
52
|
This library uses itself for type checking.
|
51
|
-
See typecheck task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`isig/irbs.rbs`](https://github.com/diaphragm/irbs/tree/master/isig
|
53
|
+
See typecheck task in [`Rakefile`](https://github.com/diaphragm/irbs/tree/master/Rakefile) and [`isig/irbs.rbs`](https://github.com/diaphragm/irbs/tree/master/sig/isig.rbs)
|
52
54
|
|
53
55
|
## Development
|
54
56
|
|
data/Rakefile
CHANGED
@@ -22,15 +22,15 @@ end
|
|
22
22
|
|
23
23
|
desc 'typecheck'
|
24
24
|
task :typecheck do
|
25
|
-
sh 'mkdir -p
|
25
|
+
sh 'mkdir -p sig'
|
26
26
|
|
27
|
-
sh 'exe/irbs "lib/**/*.rb" -o isig
|
27
|
+
sh 'exe/irbs "lib/**/*.rb" -o sig/isig.rbs'
|
28
28
|
sh 'steep check lib'
|
29
29
|
end
|
30
30
|
|
31
31
|
desc 'Example of usage with TypeProf and Steep'
|
32
32
|
task :example do
|
33
|
-
sh 'exe/irbs example/app.rb -o example/
|
34
|
-
sh 'typeprof example/app.rb example/
|
33
|
+
sh 'exe/irbs example/app.rb -o example/isig.rbs --ignore-constant'
|
34
|
+
sh 'typeprof example/app.rb example/isig.rbs -o example/typeprof.rbs'
|
35
35
|
sh 'steep check example'
|
36
36
|
end
|
data/Steepfile
CHANGED
data/example/app.rb
CHANGED
data/example/typeprof.rbs
CHANGED
data/lib/irbs/cli.rb
CHANGED
@@ -5,17 +5,18 @@ require 'optparse'
|
|
5
5
|
module Irbs
|
6
6
|
class CLI
|
7
7
|
# @sig String
|
8
|
-
|
8
|
+
IGNORE_CONSTANT_HELP_MESSAGE = 'Generate no constant signatures. ' \
|
9
9
|
'For using TypeProf. ' \
|
10
10
|
'(TypeProf genarate duplicate constant signature even if already exists.)'
|
11
|
-
private_constant :
|
11
|
+
private_constant :IGNORE_CONSTANT_HELP_MESSAGE
|
12
12
|
|
13
13
|
class << self
|
14
14
|
# @sig (Array[String]) -> void
|
15
15
|
def run(argv)
|
16
16
|
config = parse_opt(argv)
|
17
17
|
Core.new(config).generate
|
18
|
-
|
18
|
+
ensure
|
19
|
+
config&.stdout&.close
|
19
20
|
end
|
20
21
|
|
21
22
|
private
|
@@ -25,10 +26,10 @@ module Irbs
|
|
25
26
|
config = Irbs::Config.new
|
26
27
|
opt = OptionParser.new
|
27
28
|
|
28
|
-
opt.on('-o output', '
|
29
|
+
opt.on('-o output', 'Output filename. (Default: stdout)') do
|
29
30
|
config.stdout = File.open(_1, 'w')
|
30
31
|
end
|
31
|
-
opt.on('--ignore-constant',
|
32
|
+
opt.on('--ignore-constant', IGNORE_CONSTANT_HELP_MESSAGE) do
|
32
33
|
config.ingore_constant = _1
|
33
34
|
end
|
34
35
|
config.paths = opt.parse(argv)
|
data/lib/irbs/core.rb
CHANGED
@@ -11,9 +11,15 @@ module Irbs
|
|
11
11
|
def initialize(config)
|
12
12
|
@config = config
|
13
13
|
|
14
|
+
# YARD::Parser::SourceParser.after_parse_file do |parser|
|
15
|
+
# next unless parser.file == 'example/app.rb'
|
16
|
+
# $parser = parser.instance_variable_get(:@parser)
|
17
|
+
# end
|
18
|
+
|
14
19
|
YARD::Tags::Library.define_tag('Signature', :sig)
|
15
20
|
YARD::Tags::Library.define_tag('Raw rbs code', :rbs)
|
16
|
-
|
21
|
+
|
22
|
+
YARD::Parser::SourceParser.parse(config.paths)
|
17
23
|
YARD::Registry.load_all
|
18
24
|
end
|
19
25
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Irbs
|
4
|
+
# @rbs def statement: () -> untyped
|
5
|
+
module MonkeyPatch
|
6
|
+
protected
|
7
|
+
|
8
|
+
def process_mixin(mixin)
|
9
|
+
super.tap do
|
10
|
+
i = statement.method_name(true) == :include ? 0 : -1
|
11
|
+
ident = statement[0].source
|
12
|
+
_1[i].instance_variable_set(:@__ident, ident)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class YARD::Handlers::Ruby::MixinHandler # rubocop:disable Style/ClassAndModuleChildren
|
19
|
+
prepend ::Irbs::MonkeyPatch
|
20
|
+
end
|
data/lib/irbs/rbs_generator.rb
CHANGED
@@ -45,10 +45,10 @@ module Irbs
|
|
45
45
|
end
|
46
46
|
|
47
47
|
# @sig () -> String
|
48
|
-
def to_rbs # rubocop:todo Metrics/AbcSize
|
48
|
+
def to_rbs # rubocop:todo Metrics/AbcSize
|
49
49
|
[
|
50
50
|
namespace_definition,
|
51
|
-
|
51
|
+
raw_rbses.map{ Template.rbs(_1) },
|
52
52
|
class_mixins.map{ Template.extend(_1) },
|
53
53
|
instance_mixins.map{ Template.include(_1) },
|
54
54
|
config.ingore_constant ? nil : constants.map{ Template.constant(_1) },
|
@@ -64,7 +64,7 @@ module Irbs
|
|
64
64
|
end
|
65
65
|
|
66
66
|
# @sig () -> Array[YARD::Tags::Tag]
|
67
|
-
def
|
67
|
+
def raw_rbses
|
68
68
|
obj.tags(:rbs)
|
69
69
|
end
|
70
70
|
|
data/lib/irbs/template.rb
CHANGED
@@ -24,7 +24,9 @@ module Irbs
|
|
24
24
|
|
25
25
|
# @sig (YARD::CodeObjects::ModuleObject) -> String
|
26
26
|
def include(mod)
|
27
|
-
|
27
|
+
ident = mod.instance_variable_get(:@__ident)
|
28
|
+
|
29
|
+
" #{ident} ::#{mod.path}"
|
28
30
|
end
|
29
31
|
|
30
32
|
# @sig (YARD::CodeObjects::ModuleObject) -> String
|
data/lib/irbs/version.rb
CHANGED
data/lib/irbs.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative 'irbs/attribute_wrapper'
|
|
4
4
|
require_relative 'irbs/cli'
|
5
5
|
require_relative 'irbs/config'
|
6
6
|
require_relative 'irbs/core'
|
7
|
+
require_relative 'irbs/monkey_patch'
|
7
8
|
require_relative 'irbs/rbs_generator'
|
8
9
|
require_relative 'irbs/template'
|
9
10
|
require_relative 'irbs/version'
|
@@ -5,7 +5,7 @@ module ::Irbs
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class ::Irbs::CLI
|
8
|
-
|
8
|
+
IGNORE_CONSTANT_HELP_MESSAGE: String
|
9
9
|
public def self.run: (Array[String]) -> void
|
10
10
|
private def self.parse_opt: (Array[String]) -> Irbs::Config
|
11
11
|
end
|
@@ -32,6 +32,10 @@ module ::Irbs::Template
|
|
32
32
|
public def self.rbs: (YARD::Tags::Tag) -> String
|
33
33
|
end
|
34
34
|
|
35
|
+
module ::Irbs::MonkeyPatch
|
36
|
+
def statement: () -> untyped
|
37
|
+
end
|
38
|
+
|
35
39
|
class ::Irbs::RbsGenerator
|
36
40
|
extend ::Forwardable
|
37
41
|
private attr_reader obj: YARD::CodeObjects::NamespaceObject
|
@@ -44,7 +48,7 @@ class ::Irbs::RbsGenerator
|
|
44
48
|
private def writeout: () -> void
|
45
49
|
private def to_rbs: () -> String
|
46
50
|
private def namespace_definition: () -> String
|
47
|
-
private def
|
51
|
+
private def raw_rbses: () -> Array[YARD::Tags::Tag]
|
48
52
|
private def child_namespaces: () -> Array[YARD::CodeObjects::NamespaceObject]
|
49
53
|
private def constants: () -> Array[YARD::CodeObjects::ConstantObject]
|
50
54
|
private def meths: () -> Array[YARD::CodeObjects::MethodObject]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irbs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- diaphragm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -26,21 +26,22 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- Steepfile
|
28
28
|
- example/app.rb
|
29
|
-
- example/
|
29
|
+
- example/isig.rbs
|
30
30
|
- example/typeprof.rbs
|
31
31
|
- exe/irbs
|
32
32
|
- irbs.gemspec
|
33
|
-
- isig/irbs.rbs
|
34
33
|
- lib/irbs.rb
|
35
34
|
- lib/irbs/attribute_wrapper.rb
|
36
35
|
- lib/irbs/cli.rb
|
37
36
|
- lib/irbs/config.rb
|
38
37
|
- lib/irbs/core.rb
|
38
|
+
- lib/irbs/monkey_patch.rb
|
39
39
|
- lib/irbs/rbs_generator.rb
|
40
40
|
- lib/irbs/template.rb
|
41
41
|
- lib/irbs/version.rb
|
42
42
|
- rbs_collection.lock.yaml
|
43
43
|
- rbs_collection.yaml
|
44
|
+
- sig/isig.rbs
|
44
45
|
homepage: https://github.com/diaphragm/irbs
|
45
46
|
licenses:
|
46
47
|
- MIT
|