rbs_activesupport 1.2.0 → 1.3.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 +27 -10
- data/lib/rbs_activesupport/include.rb +28 -19
- data/lib/rbs_activesupport/method_searcher.rb +20 -5
- data/lib/rbs_activesupport/parser.rb +38 -2
- 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/include.rbs +11 -7
- data/sig/rbs_activesupport/method_searcher.rbs +6 -0
- data/sig/rbs_activesupport/parser.rbs +13 -1
- data/sig/rbs_activesupport/types.rbs +10 -0
- metadata +8 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef80f9fcd93b640f1a7b9f942c4e779293abb6d330b3024217c06aa9705a51a
|
4
|
+
data.tar.gz: f912a853966027885662ecefb6d676a8031986b6f045353b2d73fc2e7eaa7dec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22e1012db277a594d06677e7146cf026747928564c2cedbb3e6bc4a5d56ea293895a05259bdea5daa659b43dc11f1735afcc3e005a97f3c5279b189510e988d6
|
7
|
+
data.tar.gz: 2cadf7e6b0d9d664a43b9f17fdbb0f223417d5094c7c53eefd44272e1a347be39db0167bec410101147a9d7311b61acf577c75e99a4768cd73299bf9e048fe45
|
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
|
@@ -51,6 +51,7 @@ module RbsActivesupport
|
|
51
51
|
options[:instance_reader] = false if %i[cattr_writer mattr_writer].include?(method_call.name)
|
52
52
|
options[:instance_writer] = false if %i[cattr_reader mattr_reader].include?(method_call.name)
|
53
53
|
options[:private] = true if method_call.private?
|
54
|
+
options[:included] = method_call.included
|
54
55
|
options[:trailing_comment] = method_call.trailing_comment
|
55
56
|
methods.map do |method|
|
56
57
|
AttributeAccessor.new(method, options)
|
@@ -61,6 +62,7 @@ module RbsActivesupport
|
|
61
62
|
def build_class_attribute(method_call) #: Array[ClassAttribute]
|
62
63
|
methods, options = eval_args_with_options(method_call.args)
|
63
64
|
options[:private] = true if method_call.private?
|
65
|
+
options[:included] = method_call.included
|
64
66
|
options[:trailing_comment] = method_call.trailing_comment
|
65
67
|
methods.map do |method|
|
66
68
|
ClassAttribute.new(method, options)
|
@@ -80,7 +82,7 @@ module RbsActivesupport
|
|
80
82
|
# @rbs namespace: RBS::Namespace
|
81
83
|
# @rbs method_call: Parser::MethodCall
|
82
84
|
def build_include(namespace, method_call) #: Array[Include]
|
83
|
-
module_paths =
|
85
|
+
module_paths = eval_include_args(method_call.args)
|
84
86
|
module_paths.map do |module_path|
|
85
87
|
Include.new(namespace, module_path, { private: method_call.private? })
|
86
88
|
end
|
@@ -101,21 +103,36 @@ module RbsActivesupport
|
|
101
103
|
end
|
102
104
|
|
103
105
|
# @rbs decl: AttributeAccessor
|
104
|
-
def render_attribute_accessor(decl) #: String
|
106
|
+
def render_attribute_accessor(decl) #: String # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
105
107
|
methods = []
|
106
|
-
|
107
|
-
|
108
|
+
if decl.included?
|
109
|
+
methods << "module ClassMethods"
|
110
|
+
methods << " def #{decl.name}: () -> (#{decl.type})" if decl.singleton_reader?
|
111
|
+
methods << " def #{decl.name}=: (#{decl.type}) -> (#{decl.type})" if decl.singleton_writer?
|
112
|
+
methods << "end"
|
113
|
+
else
|
114
|
+
methods << "def self.#{decl.name}: () -> (#{decl.type})" if decl.singleton_reader?
|
115
|
+
methods << "def self.#{decl.name}=: (#{decl.type}) -> (#{decl.type})" if decl.singleton_writer?
|
116
|
+
end
|
108
117
|
methods << "def #{decl.name}: () -> (#{decl.type})" if decl.instance_reader?
|
109
118
|
methods << "def #{decl.name}=: (#{decl.type}) -> (#{decl.type})" if decl.instance_writer?
|
110
119
|
methods.join("\n")
|
111
120
|
end
|
112
121
|
|
113
122
|
# @rbs decl: ClassAttribute
|
114
|
-
def render_class_attribute(decl) #: String
|
123
|
+
def render_class_attribute(decl) #: String # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
115
124
|
methods = []
|
116
|
-
|
117
|
-
|
118
|
-
|
125
|
+
if decl.included?
|
126
|
+
methods << "module ClassMethods"
|
127
|
+
methods << " def #{decl.name}: () -> (#{decl.type})"
|
128
|
+
methods << " def #{decl.name}=: (#{decl.type}) -> (#{decl.type})"
|
129
|
+
methods << " def #{decl.name}?: () -> bool" if decl.instance_predicate?
|
130
|
+
methods << "end"
|
131
|
+
else
|
132
|
+
methods << "def self.#{decl.name}: () -> (#{decl.type})"
|
133
|
+
methods << "def self.#{decl.name}=: (#{decl.type}) -> (#{decl.type})"
|
134
|
+
methods << "def self.#{decl.name}?: () -> bool" if decl.instance_predicate?
|
135
|
+
end
|
119
136
|
methods << "def #{decl.name}: () -> (#{decl.type})" if decl.instance_reader?
|
120
137
|
methods << "def #{decl.name}=: (#{decl.type}) -> (#{decl.type})" if decl.instance_writer?
|
121
138
|
methods << "def #{decl.name}?: () -> bool" if decl.instance_predicate? && decl.instance_reader?
|
@@ -134,8 +151,8 @@ module RbsActivesupport
|
|
134
151
|
return unless decl.concern? && decl.classmethods?
|
135
152
|
|
136
153
|
<<~RBS
|
137
|
-
include #{decl.
|
138
|
-
extend #{decl.
|
154
|
+
include #{decl.module_path.to_s.delete_suffix("::")}
|
155
|
+
extend #{decl.module_path}ClassMethods
|
139
156
|
RBS
|
140
157
|
end
|
141
158
|
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,38 @@ 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
47
|
|
48
|
-
|
49
|
-
|
48
|
+
def classmethods? #: boolish
|
49
|
+
return false unless self.module
|
50
|
+
|
51
|
+
self.module&.const_defined?(:ClassMethods) || will_generate_classmethods?
|
50
52
|
end
|
51
53
|
|
52
|
-
def
|
54
|
+
def will_generate_classmethods? #: bool
|
53
55
|
return false unless module_name
|
54
56
|
|
55
|
-
|
56
|
-
|
57
|
+
path, = Object.const_source_location(module_name.to_s.delete_suffix("::")) #: String?
|
58
|
+
return false unless path && File.exist?(path)
|
59
|
+
|
60
|
+
parser = Parser.new
|
61
|
+
parser.parse(File.read(path))
|
62
|
+
method_calls = parser.method_calls[module_name] || []
|
63
|
+
return true if method_calls.any?(&:included) # steep:ignore BlockTypeMismatch
|
64
|
+
|
65
|
+
false
|
57
66
|
end
|
58
67
|
|
59
68
|
def public? #: bool
|
@@ -16,17 +16,32 @@ module RbsActivesupport
|
|
16
16
|
delegate_to = lookup_method_types(delegate.namespace.to_type_name, delegate.to)
|
17
17
|
return ["() -> untyped"] if delegate_to.any? { |t| t.type.return_type.is_a?(RBS::Types::Bases::Any) }
|
18
18
|
|
19
|
-
return_types = delegate_to
|
20
|
-
|
21
|
-
|
22
|
-
.flat_map { |t| lookup_method_types(t, delegate.method) }
|
23
|
-
.map(&:to_s)
|
19
|
+
return_types = return_type_names_for(delegate_to).uniq
|
20
|
+
.flat_map { |t| lookup_method_types(t, delegate.method) }
|
21
|
+
.map(&:to_s)
|
24
22
|
return_types << "() -> untyped" if return_types.empty?
|
25
23
|
return_types
|
26
24
|
end
|
27
25
|
|
28
26
|
private
|
29
27
|
|
28
|
+
# @rbs delegate_to: Array[RBS::MethodType]
|
29
|
+
def return_type_names_for(delegate_to) #: Array[RBS::TypeName]
|
30
|
+
delegate_to.filter_map do |t|
|
31
|
+
type_name_for(t.type.return_type)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# @rbs type: RBS::Types::t
|
36
|
+
def type_name_for(type) #: RBS::TypeName?
|
37
|
+
case type
|
38
|
+
when RBS::Types::Optional
|
39
|
+
type_name_for(type.type)
|
40
|
+
when RBS::Types::ClassSingleton, RBS::Types::ClassInstance, RBS::Types::Interface, RBS::Types::Alias
|
41
|
+
type.name
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
30
45
|
# @rbs type_name: RBS::TypeName
|
31
46
|
# @rbs method: Symbol
|
32
47
|
def lookup_method_types(type_name, method) #: Array[RBS::MethodType]
|
@@ -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
|
|
@@ -37,16 +40,22 @@ module RbsActivesupport
|
|
37
40
|
METHODS = %i[
|
38
41
|
class_attribute delegate cattr_accessor mattr_accessor cattr_reader mattr_reader cattr_writer mattr_writer include
|
39
42
|
].freeze #: Array[t] # steep:ignore IncompatibleAssignment
|
43
|
+
INCLUDED_METHODS = %i[
|
44
|
+
class_attribute cattr_accessor mattr_accessor cattr_reader mattr_reader cattr_writer mattr_writer
|
45
|
+
].freeze #: Array[Symbol]
|
40
46
|
|
41
47
|
alias process_orig process
|
42
48
|
|
43
49
|
attr_reader :comment_parser #: CommentParser
|
44
50
|
attr_reader :method_calls #: Hash[RBS::Namespace, Array[MethodCall]]
|
45
51
|
|
52
|
+
# @rbs @included: bool
|
53
|
+
|
46
54
|
def initialize #: void
|
47
55
|
super
|
48
56
|
@comment_parser = CommentParser.new
|
49
57
|
@method_calls = Hash.new { |hash, key| hash[key] = [] }
|
58
|
+
@included = false
|
50
59
|
end
|
51
60
|
|
52
61
|
# @rbs string: String
|
@@ -56,17 +65,32 @@ module RbsActivesupport
|
|
56
65
|
end
|
57
66
|
|
58
67
|
# @rbs override
|
59
|
-
def process(node, decls:, comments:, context:)
|
68
|
+
def process(node, decls:, comments:, context:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
60
69
|
case node.type
|
70
|
+
when :DEFN, :DEFS
|
71
|
+
# ignore definitions inside methods
|
61
72
|
when :FCALL, :VCALL
|
62
73
|
args = node.children[1]&.children || []
|
63
74
|
case node.children[0]
|
64
75
|
when *METHODS
|
76
|
+
return if included? && !INCLUDED_METHODS.include?(node.children[0])
|
77
|
+
|
65
78
|
@method_calls[context.namespace] << MethodCall.new(node.children[0], args, private?(decls),
|
79
|
+
included: included?,
|
66
80
|
trailing_comment: trailing_comment_for(node))
|
67
81
|
else
|
68
82
|
process_orig(node, decls: decls, comments: comments, context: context)
|
69
83
|
end
|
84
|
+
when :ITER
|
85
|
+
call = node.children[0]
|
86
|
+
if call.type == :FCALL && call.children[0] == :included && !included?
|
87
|
+
body = node.children[1].children[2]
|
88
|
+
with_included do
|
89
|
+
process(body, decls: decls, comments: comments, context: context)
|
90
|
+
end
|
91
|
+
else
|
92
|
+
process_orig(node, decls: decls, comments: comments, context: context)
|
93
|
+
end
|
70
94
|
else
|
71
95
|
process_orig(node, decls: decls, comments: comments, context: context)
|
72
96
|
end
|
@@ -81,5 +105,17 @@ module RbsActivesupport
|
|
81
105
|
def private?(decls) #: bool
|
82
106
|
current_accessibility(decls) == private
|
83
107
|
end
|
108
|
+
|
109
|
+
def included? #: bool
|
110
|
+
@included
|
111
|
+
end
|
112
|
+
|
113
|
+
# @rbs &block: () -> void
|
114
|
+
def with_included(&block) #: void
|
115
|
+
@included = true
|
116
|
+
block.call
|
117
|
+
ensure
|
118
|
+
@included = false
|
119
|
+
end
|
84
120
|
end
|
85
121
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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: 704f7e6b395fca717cc25c562598ca86015ed545
|
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] ]
|
@@ -4,24 +4,28 @@ 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
|
23
27
|
|
24
|
-
def
|
28
|
+
def will_generate_classmethods?: () -> bool
|
25
29
|
|
26
30
|
def public?: () -> bool
|
27
31
|
|
@@ -12,6 +12,12 @@ module RbsActivesupport
|
|
12
12
|
|
13
13
|
private
|
14
14
|
|
15
|
+
# @rbs delegate_to: Array[RBS::MethodType]
|
16
|
+
def return_type_names_for: (Array[RBS::MethodType] delegate_to) -> Array[RBS::TypeName]
|
17
|
+
|
18
|
+
# @rbs type: RBS::Types::t
|
19
|
+
def type_name_for: (RBS::Types::t type) -> RBS::TypeName?
|
20
|
+
|
15
21
|
# @rbs type_name: RBS::TypeName
|
16
22
|
# @rbs method: Symbol
|
17
23
|
def lookup_method_types: (RBS::TypeName type_name, Symbol method) -> Array[RBS::MethodType]
|
@@ -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
|
@@ -24,12 +27,16 @@ module RbsActivesupport
|
|
24
27
|
|
25
28
|
METHODS: Array[t]
|
26
29
|
|
30
|
+
INCLUDED_METHODS: Array[Symbol]
|
31
|
+
|
27
32
|
alias process_orig process
|
28
33
|
|
29
34
|
attr_reader comment_parser: CommentParser
|
30
35
|
|
31
36
|
attr_reader method_calls: Hash[RBS::Namespace, Array[MethodCall]]
|
32
37
|
|
38
|
+
@included: bool
|
39
|
+
|
33
40
|
def initialize: () -> void
|
34
41
|
|
35
42
|
# @rbs string: String
|
@@ -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 included?: () -> bool
|
57
|
+
|
58
|
+
# @rbs &block: () -> void
|
59
|
+
def with_included: () { () -> 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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi KOMIYA
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- i.tkomiya@gmail.com
|
58
58
|
executables: []
|
@@ -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:
|
@@ -104,7 +106,7 @@ metadata:
|
|
104
106
|
homepage_uri: https://github.com/tk0miya/rbs_activesupport
|
105
107
|
source_code_uri: https://github.com/tk0miya/rbs_activesupport
|
106
108
|
changelog_uri: https://github.com/tk0miya/rbs_activesupport
|
107
|
-
post_install_message:
|
109
|
+
post_install_message:
|
108
110
|
rdoc_options: []
|
109
111
|
require_paths:
|
110
112
|
- lib
|
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
122
|
version: '0'
|
121
123
|
requirements: []
|
122
124
|
rubygems_version: 3.5.16
|
123
|
-
signing_key:
|
125
|
+
signing_key:
|
124
126
|
specification_version: 4
|
125
127
|
summary: A RBS files generatorfor activesupport
|
126
128
|
test_files: []
|