tapioca 0.4.13 → 0.4.14
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/Gemfile +0 -1
- data/lib/tapioca/compilers/dsl/active_record_associations.rb +38 -7
- data/lib/tapioca/compilers/symbol_table/symbol_generator.rb +7 -10
- data/lib/tapioca/gemfile.rb +30 -22
- data/lib/tapioca/generator.rb +4 -0
- data/lib/tapioca/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fb77a2510082edca1c068015be8fa3d25ed500762d05ccfb4a330588a76b182
|
4
|
+
data.tar.gz: a75827dff3d7c5a49ea5d213cd7ce6b749fd4d6a4dc017bb4a8f734613a97031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d9283382edeed31a09989a789ee2441351e241558b97da8ffdb7d9a4aaa911ec8642bd5849d9b8e5800ea47ca4f9ae46b9e20cd3b0716670f25ca1304edea0b
|
7
|
+
data.tar.gz: ec2baf1e85947f754324fd06b67cf43979b8b27ccf27f21edb929f5b5758d38c8f6ceb00eec817a7219e273abb8014ae47e2d38cdbb059335e96ddb4414543a2
|
data/Gemfile
CHANGED
@@ -24,6 +24,8 @@ module Tapioca
|
|
24
24
|
# belongs_to :category
|
25
25
|
# has_many :comments
|
26
26
|
# has_one :author, class_name: "User"
|
27
|
+
#
|
28
|
+
# accepts_nested_attributes_for :category, :comments, :author
|
27
29
|
# end
|
28
30
|
# ~~~
|
29
31
|
#
|
@@ -44,6 +46,9 @@ module Tapioca
|
|
44
46
|
# sig { params(value: T.nilable(::User)).void }
|
45
47
|
# def author=(value); end
|
46
48
|
#
|
49
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
50
|
+
# def author_attributes=(attributes); end
|
51
|
+
#
|
47
52
|
# sig { params(args: T.untyped, blk: T.untyped).returns(::User) }
|
48
53
|
# def build_author(*args, &blk); end
|
49
54
|
#
|
@@ -56,6 +61,9 @@ module Tapioca
|
|
56
61
|
# sig { params(value: T.nilable(::Category)).void }
|
57
62
|
# def category=(value); end
|
58
63
|
#
|
64
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
65
|
+
# def category_attributes=(attributes); end
|
66
|
+
#
|
59
67
|
# sig { returns(T::Array[T.untyped]) }
|
60
68
|
# def comment_ids; end
|
61
69
|
#
|
@@ -68,6 +76,9 @@ module Tapioca
|
|
68
76
|
# sig { params(value: T::Enumerable[::Comment]).void }
|
69
77
|
# def comments=(value); end
|
70
78
|
#
|
79
|
+
# sig { params(attributes: T.untyped).returns(T.untyped) }
|
80
|
+
# def comments_attributes=(attributes); end
|
81
|
+
#
|
71
82
|
# sig { params(args: T.untyped, blk: T.untyped).returns(::User) }
|
72
83
|
# def create_author(*args, &blk); end
|
73
84
|
#
|
@@ -103,13 +114,8 @@ module Tapioca
|
|
103
114
|
module_name = "GeneratedAssociationMethods"
|
104
115
|
|
105
116
|
model.create_module(module_name) do |mod|
|
106
|
-
|
107
|
-
|
108
|
-
populate_collection_assoc_getter_setter(mod, constant, association_name, reflection)
|
109
|
-
else
|
110
|
-
populate_single_assoc_getter_setter(mod, constant, association_name, reflection)
|
111
|
-
end
|
112
|
-
end
|
117
|
+
populate_nested_attribute_writers(mod, constant)
|
118
|
+
populate_associations(mod, constant)
|
113
119
|
end
|
114
120
|
|
115
121
|
model.create_include(module_name)
|
@@ -123,6 +129,31 @@ module Tapioca
|
|
123
129
|
|
124
130
|
private
|
125
131
|
|
132
|
+
sig { params(mod: Parlour::RbiGenerator::Namespace, constant: T.class_of(ActiveRecord::Base)).void }
|
133
|
+
def populate_nested_attribute_writers(mod, constant)
|
134
|
+
constant.nested_attributes_options.keys.each do |association_name|
|
135
|
+
create_method(
|
136
|
+
mod,
|
137
|
+
"#{association_name}_attributes=",
|
138
|
+
parameters: [
|
139
|
+
Parlour::RbiGenerator::Parameter.new("attributes", type: "T.untyped"),
|
140
|
+
],
|
141
|
+
return_type: "T.untyped"
|
142
|
+
)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
sig { params(mod: Parlour::RbiGenerator::Namespace, constant: T.class_of(ActiveRecord::Base)).void }
|
147
|
+
def populate_associations(mod, constant)
|
148
|
+
constant.reflections.each do |association_name, reflection|
|
149
|
+
if reflection.collection?
|
150
|
+
populate_collection_assoc_getter_setter(mod, constant, association_name, reflection)
|
151
|
+
else
|
152
|
+
populate_single_assoc_getter_setter(mod, constant, association_name, reflection)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
126
157
|
sig do
|
127
158
|
params(
|
128
159
|
klass: Parlour::RbiGenerator::Namespace,
|
@@ -192,15 +192,12 @@ module Tapioca
|
|
192
192
|
def compile_module_helpers(constant)
|
193
193
|
abstract_type = T::Private::Abstract::Data.get(constant, :abstract_type)
|
194
194
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
else
|
202
|
-
""
|
203
|
-
end
|
195
|
+
helpers = []
|
196
|
+
helpers << indented("#{abstract_type}!") if abstract_type
|
197
|
+
helpers << indented("final!") if T::Private::Final.final_module?(constant)
|
198
|
+
helpers << indented("sealed!") if T::Private::Sealed.sealed_module?(constant)
|
199
|
+
|
200
|
+
helpers.join("\n")
|
204
201
|
end
|
205
202
|
|
206
203
|
sig { params(constant: Module).returns(String) }
|
@@ -210,7 +207,7 @@ module Tapioca
|
|
210
207
|
constant.props.map do |name, prop|
|
211
208
|
method = "prop"
|
212
209
|
method = "const" if prop.fetch(:immutable, false)
|
213
|
-
type = prop.fetch(:type_object, "T.untyped")
|
210
|
+
type = prop.fetch(:type_object, "T.untyped").to_s.gsub(".returns(<VOID>)", ".void")
|
214
211
|
|
215
212
|
if prop.key?(:default)
|
216
213
|
indented("#{method} :#{name}, #{type}, default: T.unsafe(nil)")
|
data/lib/tapioca/gemfile.rb
CHANGED
@@ -17,27 +17,23 @@ module Tapioca
|
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
20
|
+
sig { returns(Bundler::Definition) }
|
21
|
+
attr_reader(:definition)
|
22
|
+
|
23
|
+
sig { returns(T::Array[Gem]) }
|
24
|
+
attr_reader(:dependencies)
|
25
|
+
|
26
|
+
sig { returns(T::Array[String]) }
|
27
|
+
attr_reader(:missing_specs)
|
28
|
+
|
20
29
|
sig { void }
|
21
30
|
def initialize
|
22
31
|
@gemfile = T.let(File.new(Bundler.default_gemfile), File)
|
23
32
|
@lockfile = T.let(File.new(Bundler.default_lockfile), File)
|
24
|
-
@
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
sig { returns(T::Array[Gem]) }
|
29
|
-
def dependencies
|
30
|
-
@dependencies ||= begin
|
31
|
-
specs = definition.locked_gems.specs.to_a
|
32
|
-
|
33
|
-
definition
|
34
|
-
.resolve
|
35
|
-
.materialize(specs)
|
36
|
-
.map { |spec| Gem.new(spec) }
|
37
|
-
.reject { |gem| gem.ignore?(dir) }
|
38
|
-
.uniq(&:rbi_file_name)
|
39
|
-
.sort_by(&:rbi_file_name)
|
40
|
-
end
|
33
|
+
@definition = T.let(Bundler::Dsl.evaluate(gemfile, lockfile, {}), Bundler::Definition)
|
34
|
+
dependencies, missing_specs = load_dependencies
|
35
|
+
@dependencies = T.let(dependencies, T::Array[Gem])
|
36
|
+
@missing_specs = T.let(missing_specs, T::Array[String])
|
41
37
|
end
|
42
38
|
|
43
39
|
sig { params(gem_name: String).returns(T.nilable(Gem)) }
|
@@ -55,6 +51,23 @@ module Tapioca
|
|
55
51
|
sig { returns(File) }
|
56
52
|
attr_reader(:gemfile, :lockfile)
|
57
53
|
|
54
|
+
sig { returns([T::Array[Gem], T::Array[String]]) }
|
55
|
+
def load_dependencies
|
56
|
+
specs = definition.locked_gems.specs.to_a
|
57
|
+
|
58
|
+
missing_specs = T::Array[String].new
|
59
|
+
|
60
|
+
dependencies = definition
|
61
|
+
.resolve
|
62
|
+
.materialize(specs, missing_specs)
|
63
|
+
.map { |spec| Gem.new(spec) }
|
64
|
+
.reject { |gem| gem.ignore?(dir) }
|
65
|
+
.uniq(&:rbi_file_name)
|
66
|
+
.sort_by(&:rbi_file_name)
|
67
|
+
|
68
|
+
[dependencies, missing_specs]
|
69
|
+
end
|
70
|
+
|
58
71
|
sig { returns(Bundler::Runtime) }
|
59
72
|
def runtime
|
60
73
|
Bundler::Runtime.new(File.dirname(gemfile.path), definition)
|
@@ -65,11 +78,6 @@ module Tapioca
|
|
65
78
|
definition.groups
|
66
79
|
end
|
67
80
|
|
68
|
-
sig { returns(Bundler::Definition) }
|
69
|
-
def definition
|
70
|
-
@definition ||= Bundler::Dsl.evaluate(gemfile, lockfile, {})
|
71
|
-
end
|
72
|
-
|
73
81
|
sig { returns(String) }
|
74
82
|
def dir
|
75
83
|
File.expand_path(gemfile.path + "/..")
|
data/lib/tapioca/generator.rb
CHANGED
data/lib/tapioca/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tapioca
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ufuk Kayserilioglu
|
@@ -11,8 +11,22 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bundler
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.17.3
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.17.3
|
16
30
|
- !ruby/object:Gem::Dependency
|
17
31
|
name: pry
|
18
32
|
requirement: !ruby/object:Gem::Requirement
|