rbs_activesupport 1.2.1 → 1.4.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/README.md +28 -0
- data/lib/rbs_activesupport/ast.rb +12 -8
- data/lib/rbs_activesupport/attribute_accessor.rb +15 -0
- data/lib/rbs_activesupport/class_attribute.rb +15 -0
- data/lib/rbs_activesupport/declaration_builder.rb +29 -18
- data/lib/rbs_activesupport/include.rb +49 -20
- data/lib/rbs_activesupport/parser.rb +37 -4
- data/lib/rbs_activesupport/types.rb +40 -0
- data/lib/rbs_activesupport/version.rb +1 -1
- data/lib/rbs_activesupport.rb +1 -0
- data/rbs_collection.lock.yaml +21 -21
- data/rbs_collection.yaml +2 -0
- data/sig/rbs_activesupport/ast.rbs +1 -1
- data/sig/rbs_activesupport/attribute_accessor.rbs +6 -0
- data/sig/rbs_activesupport/class_attribute.rbs +6 -0
- data/sig/rbs_activesupport/declaration_builder.rbs +8 -5
- data/sig/rbs_activesupport/include.rbs +21 -7
- data/sig/rbs_activesupport/parser.rbs +14 -2
- data/sig/rbs_activesupport/types.rbs +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aff5090ae7c5a84c8472fe704bad2d643c7eec74367a71ade06e67fe548fbd4
|
4
|
+
data.tar.gz: 1c69a70033b144fe532c45cc313312406631a04503752f2a6deddf5a4960a3d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbe64bfcf0498b6ea9500ccfbd4f250117bff44dabedd05fc5289ae3a3ecbb027b71c3d54e2fc6032ada3301a3d82887de1892886c7fd2ae856a953cc4fc0725
|
7
|
+
data.tar.gz: 6028e5ae17c835205bd7e32e3e59d050ce2cabe0439c0e040927075626f29b7dfb4b448301fd6502d5951e05aa4b13a48c3506a8e618b73f670011b9d346a985
|
data/README.md
CHANGED
@@ -91,6 +91,34 @@ class User
|
|
91
91
|
end
|
92
92
|
```
|
93
93
|
|
94
|
+
rbs_activesupport also supports class attributes definition inside the "included" block:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
module MyConcern
|
98
|
+
extend ActiveSupport::Concern
|
99
|
+
|
100
|
+
included do
|
101
|
+
class_attribute :name
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
It is translated to the following RBS:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
module MyConcern
|
110
|
+
module ClassMethods
|
111
|
+
def name: () -> untyped
|
112
|
+
def name=: (untyped) -> untyped
|
113
|
+
def name?: () -> bool
|
114
|
+
end
|
115
|
+
|
116
|
+
def name: () -> untyped
|
117
|
+
def name=: (untyped) -> untyped
|
118
|
+
def name?: () -> bool
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
94
122
|
## Development
|
95
123
|
|
96
124
|
After checking out the repo, run `bin/setup` to install dependencies. You can also
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module RbsActivesupport
|
4
4
|
module AST
|
5
5
|
# @rbs node: Array[untyped]
|
6
|
-
def
|
7
|
-
# @type var args: Array[
|
6
|
+
def eval_include_args(node) #: Array[RBS::Namespace]
|
7
|
+
# @type var args: Array[RBS::Namespace]
|
8
8
|
*args, _ = eval_node(node)
|
9
9
|
args
|
10
10
|
end
|
@@ -22,21 +22,25 @@ module RbsActivesupport
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def eval_node(node)
|
25
|
+
def eval_node(node) # rubocop:disable Metrics/PerceivedComplexity
|
26
26
|
case node
|
27
27
|
when nil
|
28
28
|
nil
|
29
|
-
when Symbol, Hash # Only for debug use
|
29
|
+
when Symbol, Hash, RBS::Namespace # Only for debug use
|
30
30
|
node
|
31
31
|
when Array
|
32
32
|
node.map { |e| eval_node(e) }
|
33
33
|
when RubyVM::AbstractSyntaxTree::Node
|
34
34
|
case node.type
|
35
|
-
when :LIT
|
35
|
+
when :LIT, :STR
|
36
36
|
node.children.first
|
37
37
|
when :HASH
|
38
38
|
elem = node.children.first.children.compact.map { |e| eval_node(e) }
|
39
39
|
Hash[*elem]
|
40
|
+
when :ZLIST
|
41
|
+
[]
|
42
|
+
when :LIST
|
43
|
+
node.children[...-1]&.map { |e| eval_node(e) }
|
40
44
|
when :TRUE
|
41
45
|
true
|
42
46
|
when :FALSE
|
@@ -44,11 +48,11 @@ module RbsActivesupport
|
|
44
48
|
when :NIL
|
45
49
|
nil
|
46
50
|
when :CONST
|
47
|
-
node.children
|
51
|
+
RBS::Namespace.new(path: node.children, absolute: false)
|
48
52
|
when :COLON2
|
49
|
-
eval_node(node.children.first) + [node.children.last]
|
53
|
+
eval_node(node.children.first) + RBS::Namespace.new(path: [node.children.last], absolute: false)
|
50
54
|
when :COLON3
|
51
|
-
|
55
|
+
RBS::Namespace.new(path: node.children, absolute: true)
|
52
56
|
else
|
53
57
|
p node # for debug
|
54
58
|
raise
|
@@ -17,6 +17,8 @@ module RbsActivesupport
|
|
17
17
|
trailing_comment = options[:trailing_comment]
|
18
18
|
if trailing_comment&.start_with?("#:")
|
19
19
|
trailing_comment[2..].strip
|
20
|
+
elsif default?
|
21
|
+
default_type
|
20
22
|
else
|
21
23
|
"untyped"
|
22
24
|
end
|
@@ -42,6 +44,15 @@ module RbsActivesupport
|
|
42
44
|
options.fetch(:instance_writer, instance_accessor?)
|
43
45
|
end
|
44
46
|
|
47
|
+
def default? #: boolish
|
48
|
+
options.fetch(:default, nil)
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_type #: String
|
52
|
+
default = options.fetch(:default, nil)
|
53
|
+
RbsActivesupport::Types.guess_type(default)
|
54
|
+
end
|
55
|
+
|
45
56
|
def public? #: bool
|
46
57
|
!private?
|
47
58
|
end
|
@@ -49,5 +60,9 @@ module RbsActivesupport
|
|
49
60
|
def private? #: bool
|
50
61
|
options.fetch(:private, false)
|
51
62
|
end
|
63
|
+
|
64
|
+
def included? #: bool
|
65
|
+
options.fetch(:included, false)
|
66
|
+
end
|
52
67
|
end
|
53
68
|
end
|
@@ -17,6 +17,8 @@ module RbsActivesupport
|
|
17
17
|
trailing_comment = options[:trailing_comment]
|
18
18
|
if trailing_comment&.start_with?("#:")
|
19
19
|
trailing_comment[2..].strip
|
20
|
+
elsif default?
|
21
|
+
default_type
|
20
22
|
else
|
21
23
|
"untyped"
|
22
24
|
end
|
@@ -38,6 +40,15 @@ module RbsActivesupport
|
|
38
40
|
options.fetch(:instance_predicate, true)
|
39
41
|
end
|
40
42
|
|
43
|
+
def default? #: boolish
|
44
|
+
options.fetch(:default, nil)
|
45
|
+
end
|
46
|
+
|
47
|
+
def default_type #: String
|
48
|
+
default = options.fetch(:default, nil)
|
49
|
+
RbsActivesupport::Types.guess_type(default)
|
50
|
+
end
|
51
|
+
|
41
52
|
def public? #: bool
|
42
53
|
!private?
|
43
54
|
end
|
@@ -45,5 +56,9 @@ module RbsActivesupport
|
|
45
56
|
def private? #: bool
|
46
57
|
options.fetch(:private, false)
|
47
58
|
end
|
59
|
+
|
60
|
+
def included? #: bool
|
61
|
+
options.fetch(:included, false)
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
@@ -15,17 +15,19 @@ module RbsActivesupport
|
|
15
15
|
|
16
16
|
# @rbs namespace: RBS::Namespace
|
17
17
|
# @rbs method_calls: Array[Parser::MethodCall]
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
# @rbs context: RBS::Namespace?
|
19
|
+
def build(namespace, method_calls, context = nil) #: [Array[String], Array[String]]
|
20
|
+
built = build_method_calls(namespace, method_calls, context)
|
21
|
+
public_decls, private_decls = built.partition(&:public?)
|
22
|
+
[public_decls.map(&method(:render)), private_decls.map(&method(:render))] # steep:ignore BlockTypeMismatch
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
27
|
# @rbs namespace: RBS::Namespace
|
27
28
|
# @rbs method_calls: Array[Parser::MethodCall]
|
28
|
-
|
29
|
+
# @rbs context: RBS::Namespace?
|
30
|
+
def build_method_calls(namespace, method_calls, context) #: Array[t]
|
29
31
|
method_calls.flat_map do |method_call|
|
30
32
|
case method_call.name
|
31
33
|
when :class_attribute
|
@@ -35,7 +37,7 @@ module RbsActivesupport
|
|
35
37
|
when :cattr_accessor, :mattr_accessor, :cattr_reader, :mattr_reader, :cattr_writer, :mattr_writer
|
36
38
|
build_attribute_accessor(method_call)
|
37
39
|
when :include
|
38
|
-
build_include(namespace, method_call)
|
40
|
+
build_include(namespace, method_call, context)
|
39
41
|
end
|
40
42
|
rescue StandardError => e
|
41
43
|
puts "ERROR: #{namespace}:#{method_call.name}: Failed to build method calls: #{e}"
|
@@ -51,6 +53,7 @@ module RbsActivesupport
|
|
51
53
|
options[:instance_reader] = false if %i[cattr_writer mattr_writer].include?(method_call.name)
|
52
54
|
options[:instance_writer] = false if %i[cattr_reader mattr_reader].include?(method_call.name)
|
53
55
|
options[:private] = true if method_call.private?
|
56
|
+
options[:included] = method_call.included
|
54
57
|
options[:trailing_comment] = method_call.trailing_comment
|
55
58
|
methods.map do |method|
|
56
59
|
AttributeAccessor.new(method, options)
|
@@ -61,6 +64,7 @@ module RbsActivesupport
|
|
61
64
|
def build_class_attribute(method_call) #: Array[ClassAttribute]
|
62
65
|
methods, options = eval_args_with_options(method_call.args)
|
63
66
|
options[:private] = true if method_call.private?
|
67
|
+
options[:included] = method_call.included
|
64
68
|
options[:trailing_comment] = method_call.trailing_comment
|
65
69
|
methods.map do |method|
|
66
70
|
ClassAttribute.new(method, options)
|
@@ -79,15 +83,19 @@ module RbsActivesupport
|
|
79
83
|
|
80
84
|
# @rbs namespace: RBS::Namespace
|
81
85
|
# @rbs method_call: Parser::MethodCall
|
82
|
-
|
83
|
-
|
84
|
-
module_paths
|
85
|
-
|
86
|
+
# @rbs context: RBS::Namespace?
|
87
|
+
def build_include(namespace, method_call, context) #: Array[t]
|
88
|
+
module_paths = eval_include_args(method_call.args)
|
89
|
+
module_paths.flat_map do |module_path|
|
90
|
+
include = Include.new(context || namespace, module_path, { private: method_call.private? })
|
91
|
+
([include] +
|
92
|
+
build_method_calls(namespace, include.nested_includes, include.module_name) +
|
93
|
+
build_method_calls(namespace, include.method_calls_in_included_block, include.module_name))
|
86
94
|
end
|
87
95
|
end
|
88
96
|
|
89
97
|
# @rbs decl: t
|
90
|
-
def render(decl) #: String
|
98
|
+
def render(decl) #: String
|
91
99
|
case decl
|
92
100
|
when AttributeAccessor
|
93
101
|
render_attribute_accessor(decl)
|
@@ -130,13 +138,16 @@ module RbsActivesupport
|
|
130
138
|
end
|
131
139
|
|
132
140
|
# @rbs decl: Include
|
133
|
-
def render_include(decl) #: String
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
141
|
+
def render_include(decl) #: String
|
142
|
+
module_name = decl.module_name || decl.module_path
|
143
|
+
if decl.concern? && decl.classmethods?
|
144
|
+
<<~RBS
|
145
|
+
include #{module_name.to_s.delete_suffix("::")}
|
146
|
+
extend #{module_name}ClassMethods
|
147
|
+
RBS
|
148
|
+
else
|
149
|
+
"include #{module_name.to_s.delete_suffix("::")}"
|
150
|
+
end
|
140
151
|
end
|
141
152
|
end
|
142
153
|
end
|
@@ -5,11 +5,11 @@ require "active_support/concern"
|
|
5
5
|
module RbsActivesupport
|
6
6
|
class Include
|
7
7
|
attr_reader :context #: RBS::Namespace
|
8
|
-
attr_reader :module_path #:
|
8
|
+
attr_reader :module_path #: RBS::Namespace
|
9
9
|
attr_reader :options #: Hash[Symbol, untyped]
|
10
10
|
|
11
11
|
# @rbs context: RBS::Namespace
|
12
|
-
# @rbs module_path:
|
12
|
+
# @rbs module_path: RBS::Namespace
|
13
13
|
# @rbs options: Hash[Symbol, untyped]
|
14
14
|
def initialize(context, module_path, options) #: void
|
15
15
|
@context = context
|
@@ -17,20 +17,12 @@ module RbsActivesupport
|
|
17
17
|
@options = options
|
18
18
|
end
|
19
19
|
|
20
|
-
def argument #: RBS::Namespace
|
21
|
-
if module_path.first.nil?
|
22
|
-
RBS::Namespace.new(path: module_path[1...], absolute: true) # steep:ignore ArgumentTypeMismatch
|
23
|
-
else
|
24
|
-
RBS::Namespace.new(path: module_path, absolute: false) # steep:ignore ArgumentTypeMismatch
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
20
|
# @rbs %a{pure}
|
29
21
|
def module_name #: RBS::Namespace?
|
30
22
|
namespace = @context
|
31
23
|
|
32
24
|
loop do
|
33
|
-
modname = namespace +
|
25
|
+
modname = namespace + module_path
|
34
26
|
return modname if Object.const_defined?(modname.to_s.delete_suffix("::"))
|
35
27
|
|
36
28
|
break if namespace.empty?
|
@@ -39,21 +31,40 @@ module RbsActivesupport
|
|
39
31
|
end
|
40
32
|
end
|
41
33
|
|
42
|
-
|
43
|
-
|
34
|
+
# @rbs %a{pure}
|
35
|
+
def module #: Module?
|
36
|
+
return unless module_name
|
44
37
|
|
45
38
|
modname = module_name.to_s.delete_suffix("::")
|
46
|
-
return
|
39
|
+
return unless Object.const_defined?(modname)
|
40
|
+
|
41
|
+
Object.const_get(modname)
|
42
|
+
end
|
43
|
+
|
44
|
+
def concern? #: boolish
|
45
|
+
self.module&.singleton_class&.include?(ActiveSupport::Concern)
|
46
|
+
end
|
47
|
+
|
48
|
+
def classmethods? #: boolish
|
49
|
+
return false unless self.module
|
50
|
+
|
51
|
+
self.module&.const_defined?(:ClassMethods)
|
52
|
+
end
|
53
|
+
|
54
|
+
def nested_includes #: Array[Parser::MethodCall]
|
55
|
+
return [] unless module_name
|
56
|
+
return [] unless parser
|
47
57
|
|
48
|
-
|
49
|
-
|
58
|
+
method_calls = parser.method_calls[module_name] || []
|
59
|
+
method_calls.select { |call| call.name == :include && !call.included }
|
50
60
|
end
|
51
61
|
|
52
|
-
def
|
53
|
-
return
|
62
|
+
def method_calls_in_included_block #: Array[Parser::MethodCall]
|
63
|
+
return [] unless module_name
|
64
|
+
return [] unless parser
|
54
65
|
|
55
|
-
|
56
|
-
|
66
|
+
method_calls = parser.method_calls[module_name] || []
|
67
|
+
method_calls.select(&:included)
|
57
68
|
end
|
58
69
|
|
59
70
|
def public? #: bool
|
@@ -63,5 +74,23 @@ module RbsActivesupport
|
|
63
74
|
def private? #: bool
|
64
75
|
options.fetch(:private, false)
|
65
76
|
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
# @rbs @parser: Parser
|
81
|
+
|
82
|
+
# @rbs %a{pure}
|
83
|
+
def parser #: Parser?
|
84
|
+
return nil unless module_name
|
85
|
+
|
86
|
+
@parser ||= begin
|
87
|
+
path, = Object.const_source_location(module_name.to_s.delete_suffix("::")) #: String?
|
88
|
+
return nil unless path && File.exist?(path)
|
89
|
+
|
90
|
+
Parser.new(parse_included_block: true).tap do |parser|
|
91
|
+
parser.parse(File.read(path))
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
66
95
|
end
|
67
96
|
end
|
@@ -10,6 +10,7 @@ module RbsActivesupport
|
|
10
10
|
class MethodCall
|
11
11
|
attr_reader :name #: t
|
12
12
|
attr_reader :args #: Array[RubyVM::AbstractSyntaxTree::Node]
|
13
|
+
attr_reader :included #: bool
|
13
14
|
attr_reader :trailing_comment #: String?
|
14
15
|
|
15
16
|
# @rbs @private: bool
|
@@ -17,11 +18,13 @@ module RbsActivesupport
|
|
17
18
|
# @rbs name: t
|
18
19
|
# @rbs args: Array[RubyVM::AbstractSyntaxTree::Node]
|
19
20
|
# @rbs private: bool
|
21
|
+
# @rbs included: bool
|
20
22
|
# @rbs trailing_comment: String?
|
21
|
-
def initialize(name, args, private, trailing_comment: nil) #: void
|
23
|
+
def initialize(name, args, private, included: false, trailing_comment: nil) #: void
|
22
24
|
@name = name
|
23
25
|
@args = args
|
24
26
|
@private = private
|
27
|
+
@included = included
|
25
28
|
@trailing_comment = trailing_comment
|
26
29
|
end
|
27
30
|
|
@@ -42,11 +45,16 @@ module RbsActivesupport
|
|
42
45
|
|
43
46
|
attr_reader :comment_parser #: CommentParser
|
44
47
|
attr_reader :method_calls #: Hash[RBS::Namespace, Array[MethodCall]]
|
48
|
+
attr_reader :parse_included_block #: bool
|
45
49
|
|
46
|
-
|
47
|
-
|
50
|
+
# @rbs @in_included_block: bool
|
51
|
+
|
52
|
+
def initialize(parse_included_block: false) #: void
|
53
|
+
super()
|
48
54
|
@comment_parser = CommentParser.new
|
55
|
+
@parse_included_block = parse_included_block
|
49
56
|
@method_calls = Hash.new { |hash, key| hash[key] = [] }
|
57
|
+
@in_included_block = false
|
50
58
|
end
|
51
59
|
|
52
60
|
# @rbs string: String
|
@@ -56,17 +64,30 @@ module RbsActivesupport
|
|
56
64
|
end
|
57
65
|
|
58
66
|
# @rbs override
|
59
|
-
def process(node, decls:, comments:, context:)
|
67
|
+
def process(node, decls:, comments:, context:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
60
68
|
case node.type
|
69
|
+
when :DEFN, :DEFS
|
70
|
+
# ignore definitions inside methods
|
61
71
|
when :FCALL, :VCALL
|
62
72
|
args = node.children[1]&.children || []
|
63
73
|
case node.children[0]
|
64
74
|
when *METHODS
|
65
75
|
@method_calls[context.namespace] << MethodCall.new(node.children[0], args, private?(decls),
|
76
|
+
included: in_included_block?,
|
66
77
|
trailing_comment: trailing_comment_for(node))
|
67
78
|
else
|
68
79
|
process_orig(node, decls: decls, comments: comments, context: context)
|
69
80
|
end
|
81
|
+
when :ITER
|
82
|
+
call = node.children[0]
|
83
|
+
if call.type == :FCALL && call.children[0] == :included && parse_included_block && !in_included_block?
|
84
|
+
body = node.children[1].children[2]
|
85
|
+
with_included_block do
|
86
|
+
process(body, decls: decls, comments: comments, context: context)
|
87
|
+
end
|
88
|
+
else
|
89
|
+
process_orig(node, decls: decls, comments: comments, context: context)
|
90
|
+
end
|
70
91
|
else
|
71
92
|
process_orig(node, decls: decls, comments: comments, context: context)
|
72
93
|
end
|
@@ -81,5 +102,17 @@ module RbsActivesupport
|
|
81
102
|
def private?(decls) #: bool
|
82
103
|
current_accessibility(decls) == private
|
83
104
|
end
|
105
|
+
|
106
|
+
def in_included_block? #: bool
|
107
|
+
@in_included_block
|
108
|
+
end
|
109
|
+
|
110
|
+
# @rbs &block: () -> void
|
111
|
+
def with_included_block(&block) #: void
|
112
|
+
@in_included_block = true
|
113
|
+
block.call
|
114
|
+
ensure
|
115
|
+
@in_included_block = false
|
116
|
+
end
|
84
117
|
end
|
85
118
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RbsActivesupport
|
4
|
+
module Types
|
5
|
+
# @rbs!
|
6
|
+
# def self.guess_type: (untyped obj) -> String
|
7
|
+
|
8
|
+
# @rbs obj: untyped
|
9
|
+
def guess_type(obj) #: String # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
10
|
+
case obj
|
11
|
+
when nil
|
12
|
+
"nil"
|
13
|
+
when Integer, Float, Symbol, String
|
14
|
+
obj.class.name or raise
|
15
|
+
when true, false
|
16
|
+
"bool"
|
17
|
+
when Array
|
18
|
+
return "Array[untyped]" if obj.empty?
|
19
|
+
|
20
|
+
items = obj.map { |e| guess_type(e) }.uniq
|
21
|
+
if items.include?("untyped")
|
22
|
+
"Array[untyped]"
|
23
|
+
else
|
24
|
+
"Array[#{items.join(" | ")}]"
|
25
|
+
end
|
26
|
+
when Hash
|
27
|
+
return "Hash[untyped, untyped]" if obj.empty?
|
28
|
+
|
29
|
+
keys = obj.keys.map { |e| guess_type(e) }.uniq
|
30
|
+
values = obj.values.map { |e| guess_type(e) }.uniq
|
31
|
+
key_type = keys.include?("untyped") ? "untyped" : keys.join(" | ")
|
32
|
+
value_type = values.include?("untyped") ? "untyped" : values.join(" | ")
|
33
|
+
"Hash[#{key_type}, #{value_type}]"
|
34
|
+
else
|
35
|
+
"untyped"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
module_function :guess_type
|
39
|
+
end
|
40
|
+
end
|
data/lib/rbs_activesupport.rb
CHANGED
@@ -10,6 +10,7 @@ require_relative "rbs_activesupport/include"
|
|
10
10
|
require_relative "rbs_activesupport/method_searcher"
|
11
11
|
require_relative "rbs_activesupport/parser"
|
12
12
|
require_relative "rbs_activesupport/parser/comment_parser"
|
13
|
+
require_relative "rbs_activesupport/types"
|
13
14
|
require_relative "rbs_activesupport/version"
|
14
15
|
|
15
16
|
module RbsActivesupport
|
data/rbs_collection.lock.yaml
CHANGED
@@ -6,7 +6,7 @@ gems:
|
|
6
6
|
source:
|
7
7
|
type: git
|
8
8
|
name: ruby/gem_rbs_collection
|
9
|
-
revision:
|
9
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
10
10
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
11
|
repo_dir: gems
|
12
12
|
- name: actionview
|
@@ -14,7 +14,7 @@ gems:
|
|
14
14
|
source:
|
15
15
|
type: git
|
16
16
|
name: ruby/gem_rbs_collection
|
17
|
-
revision:
|
17
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
18
18
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
19
19
|
repo_dir: gems
|
20
20
|
- name: activesupport
|
@@ -22,7 +22,7 @@ gems:
|
|
22
22
|
source:
|
23
23
|
type: git
|
24
24
|
name: ruby/gem_rbs_collection
|
25
|
-
revision:
|
25
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
26
26
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
27
27
|
repo_dir: gems
|
28
28
|
- name: ast
|
@@ -30,7 +30,7 @@ gems:
|
|
30
30
|
source:
|
31
31
|
type: git
|
32
32
|
name: ruby/gem_rbs_collection
|
33
|
-
revision:
|
33
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
34
34
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
35
35
|
repo_dir: gems
|
36
36
|
- name: base64
|
@@ -50,7 +50,7 @@ gems:
|
|
50
50
|
source:
|
51
51
|
type: git
|
52
52
|
name: ruby/gem_rbs_collection
|
53
|
-
revision:
|
53
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
54
54
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
55
55
|
repo_dir: gems
|
56
56
|
- name: connection_pool
|
@@ -58,7 +58,7 @@ gems:
|
|
58
58
|
source:
|
59
59
|
type: git
|
60
60
|
name: ruby/gem_rbs_collection
|
61
|
-
revision:
|
61
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
62
62
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
63
63
|
repo_dir: gems
|
64
64
|
- name: date
|
@@ -82,7 +82,7 @@ gems:
|
|
82
82
|
source:
|
83
83
|
type: git
|
84
84
|
name: ruby/gem_rbs_collection
|
85
|
-
revision:
|
85
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
86
86
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
87
87
|
repo_dir: gems
|
88
88
|
- name: io-console
|
@@ -114,7 +114,7 @@ gems:
|
|
114
114
|
source:
|
115
115
|
type: git
|
116
116
|
name: ruby/gem_rbs_collection
|
117
|
-
revision:
|
117
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
118
118
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
119
119
|
repo_dir: gems
|
120
120
|
- name: optparse
|
@@ -126,7 +126,7 @@ gems:
|
|
126
126
|
source:
|
127
127
|
type: git
|
128
128
|
name: ruby/gem_rbs_collection
|
129
|
-
revision:
|
129
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
130
130
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
131
131
|
repo_dir: gems
|
132
132
|
- name: parser
|
@@ -134,7 +134,7 @@ gems:
|
|
134
134
|
source:
|
135
135
|
type: git
|
136
136
|
name: ruby/gem_rbs_collection
|
137
|
-
revision:
|
137
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
138
138
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
139
139
|
repo_dir: gems
|
140
140
|
- name: pathname
|
@@ -154,7 +154,7 @@ gems:
|
|
154
154
|
source:
|
155
155
|
type: git
|
156
156
|
name: ruby/gem_rbs_collection
|
157
|
-
revision:
|
157
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
158
158
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
159
159
|
repo_dir: gems
|
160
160
|
- name: rails-dom-testing
|
@@ -162,7 +162,7 @@ gems:
|
|
162
162
|
source:
|
163
163
|
type: git
|
164
164
|
name: ruby/gem_rbs_collection
|
165
|
-
revision:
|
165
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
166
166
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
167
167
|
repo_dir: gems
|
168
168
|
- name: railties
|
@@ -170,7 +170,7 @@ gems:
|
|
170
170
|
source:
|
171
171
|
type: git
|
172
172
|
name: ruby/gem_rbs_collection
|
173
|
-
revision:
|
173
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
174
174
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
175
175
|
repo_dir: gems
|
176
176
|
- name: rainbow
|
@@ -178,7 +178,7 @@ gems:
|
|
178
178
|
source:
|
179
179
|
type: git
|
180
180
|
name: ruby/gem_rbs_collection
|
181
|
-
revision:
|
181
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
182
182
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
183
183
|
repo_dir: gems
|
184
184
|
- name: rake
|
@@ -186,11 +186,11 @@ gems:
|
|
186
186
|
source:
|
187
187
|
type: git
|
188
188
|
name: ruby/gem_rbs_collection
|
189
|
-
revision:
|
189
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
190
190
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
191
191
|
repo_dir: gems
|
192
192
|
- name: rbs
|
193
|
-
version: 3.
|
193
|
+
version: 3.6.1
|
194
194
|
source:
|
195
195
|
type: rubygems
|
196
196
|
- name: rdoc
|
@@ -202,7 +202,7 @@ gems:
|
|
202
202
|
source:
|
203
203
|
type: git
|
204
204
|
name: ruby/gem_rbs_collection
|
205
|
-
revision:
|
205
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
206
206
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
207
207
|
repo_dir: gems
|
208
208
|
- name: ripper
|
@@ -214,7 +214,7 @@ gems:
|
|
214
214
|
source:
|
215
215
|
type: git
|
216
216
|
name: ruby/gem_rbs_collection
|
217
|
-
revision:
|
217
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
218
218
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
219
219
|
repo_dir: gems
|
220
220
|
- name: rubocop-ast
|
@@ -222,7 +222,7 @@ gems:
|
|
222
222
|
source:
|
223
223
|
type: git
|
224
224
|
name: ruby/gem_rbs_collection
|
225
|
-
revision:
|
225
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
226
226
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
227
227
|
repo_dir: gems
|
228
228
|
- name: securerandom
|
@@ -246,7 +246,7 @@ gems:
|
|
246
246
|
source:
|
247
247
|
type: git
|
248
248
|
name: ruby/gem_rbs_collection
|
249
|
-
revision:
|
249
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
250
250
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
251
251
|
repo_dir: gems
|
252
252
|
- name: time
|
@@ -266,7 +266,7 @@ gems:
|
|
266
266
|
source:
|
267
267
|
type: git
|
268
268
|
name: ruby/gem_rbs_collection
|
269
|
-
revision:
|
269
|
+
revision: dcc30eaed71a6e36acde3a018e6f1ffd27f72d09
|
270
270
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
271
271
|
repo_dir: gems
|
272
272
|
- name: uri
|
data/rbs_collection.yaml
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module RbsActivesupport
|
4
4
|
module AST
|
5
5
|
# @rbs node: Array[untyped]
|
6
|
-
def
|
6
|
+
def eval_include_args: (Array[untyped] node) -> Array[RBS::Namespace]
|
7
7
|
|
8
8
|
# @rbs node: Array[untyped]
|
9
9
|
def eval_args_with_options: (Array[untyped] node) -> [ Array[Symbol], Hash[Symbol, untyped] ]
|
@@ -13,13 +13,15 @@ module RbsActivesupport
|
|
13
13
|
|
14
14
|
# @rbs namespace: RBS::Namespace
|
15
15
|
# @rbs method_calls: Array[Parser::MethodCall]
|
16
|
-
|
16
|
+
# @rbs context: RBS::Namespace?
|
17
|
+
def build: (RBS::Namespace namespace, Array[Parser::MethodCall] method_calls, ?RBS::Namespace? context) -> [ Array[String], Array[String] ]
|
17
18
|
|
18
19
|
private
|
19
20
|
|
20
21
|
# @rbs namespace: RBS::Namespace
|
21
22
|
# @rbs method_calls: Array[Parser::MethodCall]
|
22
|
-
|
23
|
+
# @rbs context: RBS::Namespace?
|
24
|
+
def build_method_calls: (RBS::Namespace namespace, Array[Parser::MethodCall] method_calls, RBS::Namespace? context) -> Array[t]
|
23
25
|
|
24
26
|
# @rbs method_call: Parser::MethodCall
|
25
27
|
def build_attribute_accessor: (Parser::MethodCall method_call) -> Array[AttributeAccessor]
|
@@ -33,10 +35,11 @@ module RbsActivesupport
|
|
33
35
|
|
34
36
|
# @rbs namespace: RBS::Namespace
|
35
37
|
# @rbs method_call: Parser::MethodCall
|
36
|
-
|
38
|
+
# @rbs context: RBS::Namespace?
|
39
|
+
def build_include: (RBS::Namespace namespace, Parser::MethodCall method_call, RBS::Namespace? context) -> Array[t]
|
37
40
|
|
38
41
|
# @rbs decl: t
|
39
|
-
def render: (t decl) -> String
|
42
|
+
def render: (t decl) -> String
|
40
43
|
|
41
44
|
# @rbs decl: AttributeAccessor
|
42
45
|
def render_attribute_accessor: (AttributeAccessor decl) -> String
|
@@ -48,6 +51,6 @@ module RbsActivesupport
|
|
48
51
|
def render_delegate: (Delegate decl) -> String
|
49
52
|
|
50
53
|
# @rbs decl: Include
|
51
|
-
def render_include: (Include decl) -> String
|
54
|
+
def render_include: (Include decl) -> String
|
52
55
|
end
|
53
56
|
end
|
@@ -4,27 +4,41 @@ module RbsActivesupport
|
|
4
4
|
class Include
|
5
5
|
attr_reader context: RBS::Namespace
|
6
6
|
|
7
|
-
attr_reader module_path:
|
7
|
+
attr_reader module_path: RBS::Namespace
|
8
8
|
|
9
9
|
attr_reader options: Hash[Symbol, untyped]
|
10
10
|
|
11
11
|
# @rbs context: RBS::Namespace
|
12
|
-
# @rbs module_path:
|
12
|
+
# @rbs module_path: RBS::Namespace
|
13
13
|
# @rbs options: Hash[Symbol, untyped]
|
14
|
-
def initialize: (RBS::Namespace context,
|
15
|
-
|
16
|
-
def argument: () -> RBS::Namespace
|
14
|
+
def initialize: (RBS::Namespace context, RBS::Namespace module_path, Hash[Symbol, untyped] options) -> void
|
17
15
|
|
18
16
|
# @rbs %a{pure}
|
19
17
|
%a{pure}
|
20
18
|
def module_name: () -> RBS::Namespace?
|
21
19
|
|
22
|
-
|
20
|
+
# @rbs %a{pure}
|
21
|
+
%a{pure}
|
22
|
+
def module: () -> Module?
|
23
|
+
|
24
|
+
def concern?: () -> boolish
|
25
|
+
|
26
|
+
def classmethods?: () -> boolish
|
27
|
+
|
28
|
+
def nested_includes: () -> Array[Parser::MethodCall]
|
23
29
|
|
24
|
-
def
|
30
|
+
def method_calls_in_included_block: () -> Array[Parser::MethodCall]
|
25
31
|
|
26
32
|
def public?: () -> bool
|
27
33
|
|
28
34
|
def private?: () -> bool
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
@parser: Parser
|
39
|
+
|
40
|
+
# @rbs %a{pure}
|
41
|
+
%a{pure}
|
42
|
+
def parser: () -> Parser?
|
29
43
|
end
|
30
44
|
end
|
@@ -7,6 +7,8 @@ module RbsActivesupport
|
|
7
7
|
|
8
8
|
attr_reader args: Array[RubyVM::AbstractSyntaxTree::Node]
|
9
9
|
|
10
|
+
attr_reader included: bool
|
11
|
+
|
10
12
|
attr_reader trailing_comment: String?
|
11
13
|
|
12
14
|
@private: bool
|
@@ -14,8 +16,9 @@ module RbsActivesupport
|
|
14
16
|
# @rbs name: t
|
15
17
|
# @rbs args: Array[RubyVM::AbstractSyntaxTree::Node]
|
16
18
|
# @rbs private: bool
|
19
|
+
# @rbs included: bool
|
17
20
|
# @rbs trailing_comment: String?
|
18
|
-
def initialize: (t name, Array[RubyVM::AbstractSyntaxTree::Node] args, bool private, ?trailing_comment: String?) -> void
|
21
|
+
def initialize: (t name, Array[RubyVM::AbstractSyntaxTree::Node] args, bool private, ?included: bool, ?trailing_comment: String?) -> void
|
19
22
|
|
20
23
|
def private?: () -> bool
|
21
24
|
end
|
@@ -30,7 +33,11 @@ module RbsActivesupport
|
|
30
33
|
|
31
34
|
attr_reader method_calls: Hash[RBS::Namespace, Array[MethodCall]]
|
32
35
|
|
33
|
-
|
36
|
+
attr_reader parse_included_block: bool
|
37
|
+
|
38
|
+
@in_included_block: bool
|
39
|
+
|
40
|
+
def initialize: (?parse_included_block: untyped) -> void
|
34
41
|
|
35
42
|
# @rbs string: String
|
36
43
|
def parse: (String string) -> void
|
@@ -45,5 +52,10 @@ module RbsActivesupport
|
|
45
52
|
def private?: (Array[RBS::AST::Declarations::t | RBS::AST::Members::t] decls) -> bool
|
46
53
|
|
47
54
|
private
|
55
|
+
|
56
|
+
def in_included_block?: () -> bool
|
57
|
+
|
58
|
+
# @rbs &block: () -> void
|
59
|
+
def with_included_block: () { () -> void } -> void
|
48
60
|
end
|
49
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rbs_activesupport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi KOMIYA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/rbs_activesupport/parser.rb
|
81
81
|
- lib/rbs_activesupport/parser/comment_parser.rb
|
82
82
|
- lib/rbs_activesupport/rake_task.rb
|
83
|
+
- lib/rbs_activesupport/types.rb
|
83
84
|
- lib/rbs_activesupport/version.rb
|
84
85
|
- rbs_collection.lock.yaml
|
85
86
|
- rbs_collection.yaml
|
@@ -96,6 +97,7 @@ files:
|
|
96
97
|
- sig/rbs_activesupport/parser.rbs
|
97
98
|
- sig/rbs_activesupport/parser/comment_parser.rbs
|
98
99
|
- sig/rbs_activesupport/rake_task.rbs
|
100
|
+
- sig/rbs_activesupport/types.rbs
|
99
101
|
- sig/rbs_activesupport/version.rbs
|
100
102
|
homepage: https://github.com/tk0miya/rbs_activesupport
|
101
103
|
licenses:
|