rbs_active_hash 1.2.2 → 1.3.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 +4 -4
- data/.rubocop.yml +4 -1
- data/.vscode/settings.json +4 -1
- data/Gemfile.lock +16 -20
- data/lib/generators/rbs_active_hash/install_generator.rb +3 -1
- data/lib/rbs_active_hash/active_hash/parser.rb +114 -0
- data/lib/rbs_active_hash/active_hash.rb +29 -12
- data/lib/rbs_active_hash/version.rb +1 -1
- data/lib/rbs_active_hash.rb +1 -1
- data/rbs_active_hash.gemspec +0 -1
- data/rbs_collection.lock.yaml +16 -20
- data/sig/rbs_active_hash/active_hash/parser.rbs +28 -0
- data/sig/rbs_active_hash/active_hash.rbs +4 -1
- data/sig/rbs_active_hash/rake_task.rbs +1 -1
- metadata +4 -18
- data/lib/rbs_active_hash/associations.rb +0 -91
- data/sig/rbs_active_hash/associations.rbs +0 -21
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 49a4b12af2d15a13a338e2924494f4da8d3167301f3fa9bc66277bdf0185d326
|
|
4
|
+
data.tar.gz: 94eef0c6aafc8d0162541e51871ace002bdcd5b6f38f0203ef30eecfb19d666a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2fc036b3bd3ce01452800e183f683e6dc7a6c720d07484414c5c6cc393f9b7b8d15cef8d3819ef1ef38173b449b9cfdd892db3764e0f5468e76461f35ef557c0
|
|
7
|
+
data.tar.gz: 437b7dec163d2a770d2f916727aac06e3b1c6d2d69cae56cc1c63d756fa87b4abb12025f1b9ee9d833ccca00677bca70e062321ce8cd911fbb2f37a5ddfcca67
|
data/.rubocop.yml
CHANGED
data/.vscode/settings.json
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
rbs_active_hash (1.
|
|
4
|
+
rbs_active_hash (1.3.1)
|
|
5
5
|
active_hash
|
|
6
6
|
rbs
|
|
7
|
-
rbs_rails
|
|
8
7
|
|
|
9
8
|
GEM
|
|
10
9
|
remote: https://rubygems.org/
|
|
11
10
|
specs:
|
|
12
|
-
actionpack (7.0.7)
|
|
13
|
-
actionview (= 7.0.7)
|
|
14
|
-
activesupport (= 7.0.7)
|
|
11
|
+
actionpack (7.0.7.2)
|
|
12
|
+
actionview (= 7.0.7.2)
|
|
13
|
+
activesupport (= 7.0.7.2)
|
|
15
14
|
rack (~> 2.0, >= 2.2.4)
|
|
16
15
|
rack-test (>= 0.6.3)
|
|
17
16
|
rails-dom-testing (~> 2.0)
|
|
18
17
|
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
19
|
-
actionview (7.0.7)
|
|
20
|
-
activesupport (= 7.0.7)
|
|
18
|
+
actionview (7.0.7.2)
|
|
19
|
+
activesupport (= 7.0.7.2)
|
|
21
20
|
builder (~> 3.1)
|
|
22
21
|
erubi (~> 1.4)
|
|
23
22
|
rails-dom-testing (~> 2.0)
|
|
24
23
|
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
25
24
|
active_hash (3.2.0)
|
|
26
25
|
activesupport (>= 5.0.0)
|
|
27
|
-
activemodel (7.0.7)
|
|
28
|
-
activesupport (= 7.0.7)
|
|
29
|
-
activerecord (7.0.7)
|
|
30
|
-
activemodel (= 7.0.7)
|
|
31
|
-
activesupport (= 7.0.7)
|
|
32
|
-
activesupport (7.0.7)
|
|
26
|
+
activemodel (7.0.7.2)
|
|
27
|
+
activesupport (= 7.0.7.2)
|
|
28
|
+
activerecord (7.0.7.2)
|
|
29
|
+
activemodel (= 7.0.7.2)
|
|
30
|
+
activesupport (= 7.0.7.2)
|
|
31
|
+
activesupport (7.0.7.2)
|
|
33
32
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
34
33
|
i18n (>= 1.6, < 2)
|
|
35
34
|
minitest (>= 5.1)
|
|
@@ -80,9 +79,9 @@ GEM
|
|
|
80
79
|
rails-html-sanitizer (1.6.0)
|
|
81
80
|
loofah (~> 2.21)
|
|
82
81
|
nokogiri (~> 1.14)
|
|
83
|
-
railties (7.0.7)
|
|
84
|
-
actionpack (= 7.0.7)
|
|
85
|
-
activesupport (= 7.0.7)
|
|
82
|
+
railties (7.0.7.2)
|
|
83
|
+
actionpack (= 7.0.7.2)
|
|
84
|
+
activesupport (= 7.0.7.2)
|
|
86
85
|
method_source
|
|
87
86
|
rake (>= 12.2)
|
|
88
87
|
thor (~> 1.0)
|
|
@@ -93,9 +92,6 @@ GEM
|
|
|
93
92
|
rb-inotify (0.10.1)
|
|
94
93
|
ffi (~> 1.0)
|
|
95
94
|
rbs (3.1.3)
|
|
96
|
-
rbs_rails (0.12.0)
|
|
97
|
-
parser
|
|
98
|
-
rbs (>= 1)
|
|
99
95
|
regexp_parser (2.8.1)
|
|
100
96
|
rexml (3.2.6)
|
|
101
97
|
rspec (3.12.0)
|
|
@@ -114,7 +110,7 @@ GEM
|
|
|
114
110
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
115
111
|
rspec-support (~> 3.12.0)
|
|
116
112
|
rspec-support (3.12.0)
|
|
117
|
-
rubocop (1.56.
|
|
113
|
+
rubocop (1.56.1)
|
|
118
114
|
base64 (~> 0.1.1)
|
|
119
115
|
json (~> 2.3)
|
|
120
116
|
language_server-protocol (>= 3.17.0)
|
|
@@ -6,8 +6,10 @@ module RbsActiveHash
|
|
|
6
6
|
class InstallGenerator < Rails::Generators::Base
|
|
7
7
|
def create_raketask
|
|
8
8
|
create_file "lib/tasks/rbs_active_hash.rake", <<~RUBY
|
|
9
|
+
# frozen_string_literal: true
|
|
10
|
+
|
|
9
11
|
begin
|
|
10
|
-
require
|
|
12
|
+
require "rbs_active_hash/rake_task"
|
|
11
13
|
|
|
12
14
|
RbsActiveHash::RakeTask.new
|
|
13
15
|
rescue LoadError
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rbs"
|
|
4
|
+
|
|
5
|
+
module RbsActiveHash
|
|
6
|
+
module ActiveHash
|
|
7
|
+
module Parser
|
|
8
|
+
class AssociationDefinition < RBS::AST::Members::Include
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ScopeDefinition < RBS::AST::Members::Include
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class RB < RBS::Prototype::RB
|
|
15
|
+
def process(node, decls:, comments:, context:)
|
|
16
|
+
case node.type
|
|
17
|
+
when :FCALL, :VCALL
|
|
18
|
+
case node.children.first
|
|
19
|
+
when :has_many, :has_one, :belongs_to
|
|
20
|
+
decls << AssociationDefinition.new(
|
|
21
|
+
name: RBS::TypeName.new(name: node.children.first, namespace: RBS::Namespace.root),
|
|
22
|
+
args: node.children[1],
|
|
23
|
+
annotations: [],
|
|
24
|
+
location: nil,
|
|
25
|
+
comment: nil
|
|
26
|
+
)
|
|
27
|
+
when :scope
|
|
28
|
+
decls << ScopeDefinition.new(
|
|
29
|
+
name: RBS::TypeName.new(name: node.children.first, namespace: RBS::Namespace.root),
|
|
30
|
+
args: node.children[1],
|
|
31
|
+
annotations: [],
|
|
32
|
+
location: nil,
|
|
33
|
+
comment: nil
|
|
34
|
+
)
|
|
35
|
+
else
|
|
36
|
+
super
|
|
37
|
+
end
|
|
38
|
+
else
|
|
39
|
+
super
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
class Parser
|
|
45
|
+
attr_reader :has_many, :has_one, :belongs_to, :scopes
|
|
46
|
+
|
|
47
|
+
def initialize
|
|
48
|
+
@has_many = []
|
|
49
|
+
@has_one = []
|
|
50
|
+
@belongs_to = []
|
|
51
|
+
@scopes = []
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def parse(string, target)
|
|
55
|
+
parser = RB.new
|
|
56
|
+
parser.parse(string)
|
|
57
|
+
parser.decls.each do |decl|
|
|
58
|
+
process(decl, target)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def process(node, target)
|
|
63
|
+
case node
|
|
64
|
+
when RBS::AST::Declarations::Module, RBS::AST::Declarations::Class
|
|
65
|
+
name = node.name.split
|
|
66
|
+
if target[...name.size] == name
|
|
67
|
+
node.members.each do |member|
|
|
68
|
+
process(member, target[name.size...].to_a)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
when AssociationDefinition
|
|
72
|
+
process_association_definition(node) if target.empty?
|
|
73
|
+
when ScopeDefinition
|
|
74
|
+
process_scope_definition(node) if target.empty?
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def process_association_definition(node)
|
|
79
|
+
case node.name.name
|
|
80
|
+
when :has_many
|
|
81
|
+
association_id, args = node_to_literal(node.args)
|
|
82
|
+
@has_many << [association_id, args.to_h]
|
|
83
|
+
when :has_one
|
|
84
|
+
association_id, args = node_to_literal(node.args)
|
|
85
|
+
@has_one << [association_id, args.to_h]
|
|
86
|
+
when :belongs_to
|
|
87
|
+
association_id, args = node_to_literal(node.args)
|
|
88
|
+
@belongs_to << [association_id, args.to_h]
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def process_scope_definition(node)
|
|
93
|
+
scope_id, args = node_to_literal(node.args)
|
|
94
|
+
@scopes << [scope_id, args.to_h]
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def node_to_literal(node)
|
|
98
|
+
case node.type
|
|
99
|
+
when :LIST
|
|
100
|
+
node.children[...-1].map { |child| node_to_literal(child) }
|
|
101
|
+
when :LIT, :STR
|
|
102
|
+
node.children.first
|
|
103
|
+
when :HASH
|
|
104
|
+
Hash[*node_to_literal(node.children.first)]
|
|
105
|
+
when :LAMBDA
|
|
106
|
+
{} # Convert to empty hash because rbs_active_hash does not process lambda
|
|
107
|
+
else
|
|
108
|
+
node
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "rbs"
|
|
4
|
-
require "rbs_rails/util"
|
|
5
4
|
require "active_hash"
|
|
6
5
|
|
|
7
6
|
module RbsActiveHash
|
|
@@ -15,15 +14,21 @@ module RbsActiveHash
|
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
class Generator
|
|
18
|
-
attr_reader :klass, :klass_name
|
|
17
|
+
attr_reader :klass, :klass_name, :parser
|
|
19
18
|
|
|
20
19
|
def initialize(klass)
|
|
21
20
|
@klass = klass
|
|
22
|
-
@klass_name =
|
|
21
|
+
@klass_name = klass.name || ""
|
|
22
|
+
@parser = ActiveHash::Parser::Parser.new
|
|
23
|
+
|
|
24
|
+
path, = Object.const_source_location(klass_name)
|
|
25
|
+
return unless path
|
|
26
|
+
|
|
27
|
+
@parser.parse(IO.read(path.to_s), klass_name.split("::").map(&:to_sym))
|
|
23
28
|
end
|
|
24
29
|
|
|
25
30
|
def generate
|
|
26
|
-
if klass
|
|
31
|
+
if klass < ::ActiveFile::Base
|
|
27
32
|
begin
|
|
28
33
|
klass.reload
|
|
29
34
|
rescue StandardError
|
|
@@ -31,15 +36,23 @@ module RbsActiveHash
|
|
|
31
36
|
end
|
|
32
37
|
end
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
format(klass_decl)
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
private
|
|
38
43
|
|
|
44
|
+
def format(rbs)
|
|
45
|
+
parsed = RBS::Parser.parse_signature(rbs)
|
|
46
|
+
StringIO.new.tap do |out|
|
|
47
|
+
RBS::Writer.new(out: out).write(parsed[1] + parsed[2])
|
|
48
|
+
end.string
|
|
49
|
+
end
|
|
50
|
+
|
|
39
51
|
def klass_decl
|
|
40
52
|
<<~RBS
|
|
41
53
|
#{header}
|
|
42
54
|
#{enum_decls}
|
|
55
|
+
#{scope_decls}
|
|
43
56
|
#{association_decls}
|
|
44
57
|
#{method_decls}
|
|
45
58
|
#{footer}
|
|
@@ -55,7 +68,7 @@ module RbsActiveHash
|
|
|
55
68
|
when Class
|
|
56
69
|
# @type var superclass: Class
|
|
57
70
|
superclass = _ = mod_object.superclass
|
|
58
|
-
superclass_name =
|
|
71
|
+
superclass_name = superclass.name || "Object"
|
|
59
72
|
|
|
60
73
|
"class #{mod_name} < ::#{superclass_name}"
|
|
61
74
|
when Module
|
|
@@ -98,14 +111,18 @@ module RbsActiveHash
|
|
|
98
111
|
end
|
|
99
112
|
end
|
|
100
113
|
|
|
101
|
-
def
|
|
102
|
-
return
|
|
114
|
+
def scope_decls
|
|
115
|
+
return if parser.scopes.empty?
|
|
103
116
|
|
|
104
|
-
|
|
105
|
-
|
|
117
|
+
parser.scopes.map do |scope_id, _|
|
|
118
|
+
<<~RBS
|
|
119
|
+
def self.#{scope_id}: () -> ActiveHash::Relation[instance]
|
|
120
|
+
RBS
|
|
121
|
+
end.join("\n")
|
|
122
|
+
end
|
|
106
123
|
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
def association_decls
|
|
125
|
+
return unless klass.ancestors.include? ::ActiveHash::Associations
|
|
109
126
|
|
|
110
127
|
<<~RBS
|
|
111
128
|
include ActiveHash::Associations
|
data/lib/rbs_active_hash.rb
CHANGED
data/rbs_active_hash.gemspec
CHANGED
|
@@ -29,7 +29,6 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
|
|
30
30
|
spec.add_dependency "active_hash"
|
|
31
31
|
spec.add_dependency "rbs"
|
|
32
|
-
spec.add_dependency "rbs_rails"
|
|
33
32
|
|
|
34
33
|
# For more information and examples about making a new gem, check out our
|
|
35
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
data/rbs_collection.lock.yaml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
sources:
|
|
3
3
|
- type: git
|
|
4
4
|
name: ruby/gem_rbs_collection
|
|
5
|
-
revision:
|
|
5
|
+
revision: 5666e737d2b27a8425b4e3855c1a38cae54989f7
|
|
6
6
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
7
7
|
repo_dir: gems
|
|
8
8
|
path: ".gem_rbs_collection"
|
|
@@ -16,7 +16,7 @@ gems:
|
|
|
16
16
|
source:
|
|
17
17
|
type: git
|
|
18
18
|
name: ruby/gem_rbs_collection
|
|
19
|
-
revision:
|
|
19
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
20
20
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
21
21
|
repo_dir: gems
|
|
22
22
|
- name: actionview
|
|
@@ -24,7 +24,7 @@ gems:
|
|
|
24
24
|
source:
|
|
25
25
|
type: git
|
|
26
26
|
name: ruby/gem_rbs_collection
|
|
27
|
-
revision:
|
|
27
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
28
28
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
29
29
|
repo_dir: gems
|
|
30
30
|
- name: active_hash
|
|
@@ -32,7 +32,7 @@ gems:
|
|
|
32
32
|
source:
|
|
33
33
|
type: git
|
|
34
34
|
name: ruby/gem_rbs_collection
|
|
35
|
-
revision:
|
|
35
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
36
36
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
37
37
|
repo_dir: gems
|
|
38
38
|
- name: activemodel
|
|
@@ -40,7 +40,7 @@ gems:
|
|
|
40
40
|
source:
|
|
41
41
|
type: git
|
|
42
42
|
name: ruby/gem_rbs_collection
|
|
43
|
-
revision:
|
|
43
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
44
44
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
45
45
|
repo_dir: gems
|
|
46
46
|
- name: activerecord
|
|
@@ -48,7 +48,7 @@ gems:
|
|
|
48
48
|
source:
|
|
49
49
|
type: git
|
|
50
50
|
name: ruby/gem_rbs_collection
|
|
51
|
-
revision:
|
|
51
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
52
52
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
53
53
|
repo_dir: gems
|
|
54
54
|
- name: activesupport
|
|
@@ -56,7 +56,7 @@ gems:
|
|
|
56
56
|
source:
|
|
57
57
|
type: git
|
|
58
58
|
name: ruby/gem_rbs_collection
|
|
59
|
-
revision:
|
|
59
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
60
60
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
61
61
|
repo_dir: gems
|
|
62
62
|
- name: ast
|
|
@@ -64,7 +64,7 @@ gems:
|
|
|
64
64
|
source:
|
|
65
65
|
type: git
|
|
66
66
|
name: ruby/gem_rbs_collection
|
|
67
|
-
revision:
|
|
67
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
68
68
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
69
69
|
repo_dir: gems
|
|
70
70
|
- name: base64
|
|
@@ -80,7 +80,7 @@ gems:
|
|
|
80
80
|
source:
|
|
81
81
|
type: git
|
|
82
82
|
name: ruby/gem_rbs_collection
|
|
83
|
-
revision:
|
|
83
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
84
84
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
85
85
|
repo_dir: gems
|
|
86
86
|
- name: date
|
|
@@ -92,7 +92,7 @@ gems:
|
|
|
92
92
|
source:
|
|
93
93
|
type: git
|
|
94
94
|
name: ruby/gem_rbs_collection
|
|
95
|
-
revision:
|
|
95
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
96
96
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
97
97
|
repo_dir: gems
|
|
98
98
|
- name: json
|
|
@@ -120,7 +120,7 @@ gems:
|
|
|
120
120
|
source:
|
|
121
121
|
type: git
|
|
122
122
|
name: ruby/gem_rbs_collection
|
|
123
|
-
revision:
|
|
123
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
124
124
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
125
125
|
repo_dir: gems
|
|
126
126
|
- name: optparse
|
|
@@ -132,7 +132,7 @@ gems:
|
|
|
132
132
|
source:
|
|
133
133
|
type: git
|
|
134
134
|
name: ruby/gem_rbs_collection
|
|
135
|
-
revision:
|
|
135
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
136
136
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
137
137
|
repo_dir: gems
|
|
138
138
|
- name: pathname
|
|
@@ -144,7 +144,7 @@ gems:
|
|
|
144
144
|
source:
|
|
145
145
|
type: git
|
|
146
146
|
name: ruby/gem_rbs_collection
|
|
147
|
-
revision:
|
|
147
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
148
148
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
149
149
|
repo_dir: gems
|
|
150
150
|
- name: rails-dom-testing
|
|
@@ -152,7 +152,7 @@ gems:
|
|
|
152
152
|
source:
|
|
153
153
|
type: git
|
|
154
154
|
name: ruby/gem_rbs_collection
|
|
155
|
-
revision:
|
|
155
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
156
156
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
157
157
|
repo_dir: gems
|
|
158
158
|
- name: railties
|
|
@@ -160,7 +160,7 @@ gems:
|
|
|
160
160
|
source:
|
|
161
161
|
type: git
|
|
162
162
|
name: ruby/gem_rbs_collection
|
|
163
|
-
revision:
|
|
163
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
164
164
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
165
165
|
repo_dir: gems
|
|
166
166
|
- name: rainbow
|
|
@@ -168,17 +168,13 @@ gems:
|
|
|
168
168
|
source:
|
|
169
169
|
type: git
|
|
170
170
|
name: ruby/gem_rbs_collection
|
|
171
|
-
revision:
|
|
171
|
+
revision: 306d1aec19defeb177e217d8aad9812a52bcd5eb
|
|
172
172
|
remote: https://github.com/ruby/gem_rbs_collection.git
|
|
173
173
|
repo_dir: gems
|
|
174
174
|
- name: rbs
|
|
175
175
|
version: 3.1.3
|
|
176
176
|
source:
|
|
177
177
|
type: rubygems
|
|
178
|
-
- name: rbs_rails
|
|
179
|
-
version: 0.12.0
|
|
180
|
-
source:
|
|
181
|
-
type: rubygems
|
|
182
178
|
- name: rdoc
|
|
183
179
|
version: '0'
|
|
184
180
|
source:
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module RbsActiveHash
|
|
2
|
+
module ActiveHash
|
|
3
|
+
module Parser
|
|
4
|
+
class AssociationDefinition < RBS::AST::Members::Include
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class ScopeDefinition < RBS::AST::Members::Include
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class RB < RBS::Prototype::RB
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class Parser
|
|
14
|
+
attr_reader has_many: Array[[Symbol, Hash[untyped, untyped]]]
|
|
15
|
+
attr_reader has_one: Array[[Symbol, Hash[untyped, untyped]]]
|
|
16
|
+
attr_reader belongs_to: Array[[Symbol, Hash[untyped, untyped]]]
|
|
17
|
+
attr_reader scopes: Array[[Symbol, Hash[untyped, untyped]]]
|
|
18
|
+
|
|
19
|
+
def initialize: () -> void
|
|
20
|
+
def parse: (String string, Array[Symbol] target) -> void
|
|
21
|
+
def process: (RBS::AST::Declarations::t | RBS::AST::Members::t node, Array[Symbol] target) -> void
|
|
22
|
+
def process_association_definition: (AssociationDefinition node) -> void
|
|
23
|
+
def process_scope_definition: (ScopeDefinition node) -> void
|
|
24
|
+
def node_to_literal: (untyped node) -> untyped
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -6,16 +6,19 @@ module RbsActiveHash
|
|
|
6
6
|
class Generator
|
|
7
7
|
attr_reader klass: singleton(ActiveHash::Base)
|
|
8
8
|
attr_reader klass_name: String
|
|
9
|
+
attr_reader parser: ActiveHash::Parser::Parser
|
|
9
10
|
|
|
10
11
|
def initialize: (singleton(ActiveHash::Base) klass) -> void
|
|
11
12
|
def generate: () -> String
|
|
12
13
|
|
|
13
14
|
private
|
|
14
15
|
|
|
16
|
+
def format: (String) -> String
|
|
15
17
|
def klass_decl: () -> String
|
|
16
18
|
def header: () -> String
|
|
17
19
|
def enum_decls: () -> String?
|
|
18
20
|
def constants: () -> Array[String]
|
|
21
|
+
def scope_decls: () -> String?
|
|
19
22
|
def association_decls: () -> String?
|
|
20
23
|
def has_many_decls: (Array[[Symbol, Hash[untyped, untyped]]]) -> String
|
|
21
24
|
def has_one_decls: (Array[[Symbol, Hash[untyped, untyped]]]) -> String
|
|
@@ -23,7 +26,7 @@ module RbsActiveHash
|
|
|
23
26
|
def method_decls: () -> String
|
|
24
27
|
def method_names: () -> Array[Symbol]
|
|
25
28
|
def method_types: () -> Hash[Symbol, untyped]
|
|
26
|
-
def valid_field_name?: (String) -> boolish
|
|
29
|
+
def valid_field_name?: (String | Symbol) -> boolish
|
|
27
30
|
def footer: () -> String
|
|
28
31
|
|
|
29
32
|
def identify_class: (untyped value) -> (String | singleton(Class))
|
|
@@ -6,7 +6,7 @@ module RbsActiveHash
|
|
|
6
6
|
@name: Symbol
|
|
7
7
|
@signature_root_dir: Pathname
|
|
8
8
|
|
|
9
|
-
def initialize: (Symbol name) { (RakeTask) -> void } -> void
|
|
9
|
+
def initialize: (?Symbol name) { (RakeTask) -> void } -> void
|
|
10
10
|
def define_setup_task: () -> void
|
|
11
11
|
def define_clean_task: () -> void
|
|
12
12
|
def define_generate_task: () -> void
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rbs_active_hash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Takeshi KOMIYA
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-
|
|
11
|
+
date: 2023-09-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_hash
|
|
@@ -38,20 +38,6 @@ dependencies:
|
|
|
38
38
|
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
|
-
- !ruby/object:Gem::Dependency
|
|
42
|
-
name: rbs_rails
|
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
|
44
|
-
requirements:
|
|
45
|
-
- - ">="
|
|
46
|
-
- !ruby/object:Gem::Version
|
|
47
|
-
version: '0'
|
|
48
|
-
type: :runtime
|
|
49
|
-
prerelease: false
|
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
-
requirements:
|
|
52
|
-
- - ">="
|
|
53
|
-
- !ruby/object:Gem::Version
|
|
54
|
-
version: '0'
|
|
55
41
|
description: A RBS files generator for ActiveHash models
|
|
56
42
|
email:
|
|
57
43
|
- i.tkomiya@gmail.com
|
|
@@ -72,7 +58,7 @@ files:
|
|
|
72
58
|
- lib/generators/rbs_active_hash/install_generator.rb
|
|
73
59
|
- lib/rbs_active_hash.rb
|
|
74
60
|
- lib/rbs_active_hash/active_hash.rb
|
|
75
|
-
- lib/rbs_active_hash/
|
|
61
|
+
- lib/rbs_active_hash/active_hash/parser.rb
|
|
76
62
|
- lib/rbs_active_hash/rake_task.rb
|
|
77
63
|
- lib/rbs_active_hash/version.rb
|
|
78
64
|
- rbs_active_hash.gemspec
|
|
@@ -81,7 +67,7 @@ files:
|
|
|
81
67
|
- sig/generators/rbs_active_hash/install_generator.rbs
|
|
82
68
|
- sig/rbs_active_hash.rbs
|
|
83
69
|
- sig/rbs_active_hash/active_hash.rbs
|
|
84
|
-
- sig/rbs_active_hash/
|
|
70
|
+
- sig/rbs_active_hash/active_hash/parser.rbs
|
|
85
71
|
- sig/rbs_active_hash/rake_task.rbs
|
|
86
72
|
- sig/shims/rake.rbs
|
|
87
73
|
- sig/shims/thor.rbs
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "rbs"
|
|
4
|
-
|
|
5
|
-
module RbsActiveHash
|
|
6
|
-
module Associations
|
|
7
|
-
class AssociationDefinition < RBS::AST::Members::Include
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
class RB < RBS::Prototype::RB
|
|
11
|
-
def process(node, decls:, comments:, context:)
|
|
12
|
-
case node.type
|
|
13
|
-
when :FCALL, :VCALL
|
|
14
|
-
case node.children.first
|
|
15
|
-
when :has_many, :has_one, :belongs_to
|
|
16
|
-
decls << AssociationDefinition.new(
|
|
17
|
-
name: RBS::TypeName.new(name: node.children.first, namespace: RBS::Namespace.root),
|
|
18
|
-
args: node.children[1],
|
|
19
|
-
annotations: [],
|
|
20
|
-
location: nil,
|
|
21
|
-
comment: nil
|
|
22
|
-
)
|
|
23
|
-
else
|
|
24
|
-
super
|
|
25
|
-
end
|
|
26
|
-
else
|
|
27
|
-
super
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
class Parser
|
|
33
|
-
attr_reader :has_many, :has_one, :belongs_to
|
|
34
|
-
|
|
35
|
-
def initialize
|
|
36
|
-
@has_many = []
|
|
37
|
-
@has_one = []
|
|
38
|
-
@belongs_to = []
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def parse(string, target)
|
|
42
|
-
parser = RB.new
|
|
43
|
-
parser.parse(string)
|
|
44
|
-
parser.decls.each do |decl|
|
|
45
|
-
process(decl, target)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def process(node, target)
|
|
50
|
-
case node
|
|
51
|
-
when RBS::AST::Declarations::Module, RBS::AST::Declarations::Class
|
|
52
|
-
name = node.name.split
|
|
53
|
-
if target[...name.size] == name
|
|
54
|
-
node.members.each do |member|
|
|
55
|
-
process(member, target[name.size...].to_a)
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
when AssociationDefinition
|
|
59
|
-
process_association_definition(node) if target.empty?
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
def process_association_definition(node)
|
|
64
|
-
case node.name.name
|
|
65
|
-
when :has_many
|
|
66
|
-
association_id, args = node_to_literal(node.args)
|
|
67
|
-
@has_many << [association_id, args.to_h]
|
|
68
|
-
when :has_one
|
|
69
|
-
association_id, args = node_to_literal(node.args)
|
|
70
|
-
@has_one << [association_id, args.to_h]
|
|
71
|
-
when :belongs_to
|
|
72
|
-
association_id, args = node_to_literal(node.args)
|
|
73
|
-
@belongs_to << [association_id, args.to_h]
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def node_to_literal(node)
|
|
78
|
-
case node.type
|
|
79
|
-
when :LIST
|
|
80
|
-
node.children[...-1].map { |child| node_to_literal(child) }
|
|
81
|
-
when :LIT, :STR
|
|
82
|
-
node.children.first
|
|
83
|
-
when :HASH
|
|
84
|
-
Hash[*node_to_literal(node.children.first)]
|
|
85
|
-
else
|
|
86
|
-
node
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
module RbsActiveHash
|
|
2
|
-
module Associations
|
|
3
|
-
class AssociationDefinition < RBS::AST::Members::Include
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
class RB < RBS::Prototype::RB
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Parser
|
|
10
|
-
attr_reader has_many: Array[[Symbol, Hash[untyped, untyped]]]
|
|
11
|
-
attr_reader has_one: Array[[Symbol, Hash[untyped, untyped]]]
|
|
12
|
-
attr_reader belongs_to: Array[[Symbol, Hash[untyped, untyped]]]
|
|
13
|
-
|
|
14
|
-
def initialize: () -> void
|
|
15
|
-
def parse: (String string, Array[Symbol] target) -> void
|
|
16
|
-
def process: (RBS::AST::Declarations::t | RBS::AST::Members::t node, Array[Symbol] target) -> void
|
|
17
|
-
def process_association_definition: (AssociationDefinition node) -> void
|
|
18
|
-
def node_to_literal: (untyped node) -> untyped
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|