tapioca 0.15.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f93b130a7096e0712ccd91b8406d92ce537287afafc8aad7586e7f670d88a131
4
- data.tar.gz: b2cc1e6d2658002600c1edd9c5c88b22704e3f4170ff19aff93bb9fc21df688e
3
+ metadata.gz: 12203d783fb506aff6b357dc3dc02fd7f9d9e7147fd2fb715329a5311ff96bf6
4
+ data.tar.gz: 0ac885bad578baec1701f6b2f46e48ca5f12e4c5d8fd9840d63195291400a430
5
5
  SHA512:
6
- metadata.gz: aa10ff7ffd4768cea802b63dc68273fa0abf7f69b61a83b1325669e97d706cb8afcc704093c93596a830662fe04b01ad2ded3c166abd69a5c69097bd28f586c9
7
- data.tar.gz: 63499428de9374990372beb46ece3f98d0f446ba28ef02bfa181179113e37e587ff9867bbe0d729d67c03ddb2813943f6f04d14f2065589a603a766a06ce8096
6
+ metadata.gz: f42230c7ca6b96bb6ed299faa2b4c8d8f87ae44244a6501006c55b22c6307b9a0b777cdbb8d713f6ee3320d44502428c17ddf86dd85929be842433557d3e3793
7
+ data.tar.gz: df6f57d7c1446e70bd759bc84c5fa06f5985e01783be8d8f7655e06e3045c5de17cc1e931d4f0b5d78bc19f867de61dc228c77eb2f4df325038e09d908e2efd0
@@ -147,7 +147,7 @@ module Tapioca
147
147
  machine.create_method(
148
148
  method,
149
149
  parameters: [
150
- create_opt_param("symbol", type: "T.nilable(Symbol)", default: "nil"),
150
+ create_rest_param("callbacks", type: "T.any(String, Symbol, T::Class[T.anything], Proc)"),
151
151
  create_block_param("block", type: "T.nilable(T.proc.bind(#{constant_name}).void)"),
152
152
  ],
153
153
  )
@@ -104,7 +104,7 @@ module Tapioca
104
104
 
105
105
  column = @constant.columns_hash[column_name]
106
106
  column_type = @constant.attribute_types[column_name]
107
- getter_type = type_for_activerecord_value(column_type)
107
+ getter_type = type_for_activerecord_value(column_type, column_nullability: !!column&.null)
108
108
  setter_type =
109
109
  case column_type
110
110
  when ActiveRecord::Enum::EnumType
@@ -121,8 +121,8 @@ module Tapioca
121
121
  end
122
122
  end
123
123
 
124
- sig { params(column_type: T.untyped).returns(String) }
125
- def type_for_activerecord_value(column_type)
124
+ sig { params(column_type: T.untyped, column_nullability: T::Boolean).returns(String) }
125
+ def type_for_activerecord_value(column_type, column_nullability:)
126
126
  case column_type
127
127
  when ->(type) { defined?(MoneyColumn) && MoneyColumn::ActiveRecordType === type }
128
128
  "::Money"
@@ -133,11 +133,12 @@ module Tapioca
133
133
  }
134
134
  # Reflect to see if `ActiveModel::Type::Value` is being used first.
135
135
  getter_type = Tapioca::Dsl::Helpers::ActiveModelTypeHelper.type_for(column_type)
136
- return getter_type unless getter_type == "T.untyped"
137
136
 
138
- # Otherwise fallback to String as `ActiveRecord::Encryption::EncryptedAttributeType` inherits from
137
+ # Fallback to String as `ActiveRecord::Encryption::EncryptedAttributeType` inherits from
139
138
  # `ActiveRecord::Type::Text` which inherits from `ActiveModel::Type::String`.
140
- "::String"
139
+ return "::String" if getter_type == "T.untyped"
140
+
141
+ as_non_nilable_if_persisted_and_not_nullable(getter_type, column_nullability:)
141
142
  when ActiveRecord::Type::String
142
143
  "::String"
143
144
  when ActiveRecord::Type::Date
@@ -160,7 +161,7 @@ module Tapioca
160
161
  defined?(ActiveRecord::Normalization::NormalizedValueType) &&
161
162
  ActiveRecord::Normalization::NormalizedValueType === type
162
163
  }
163
- type_for_activerecord_value(column_type.cast_type)
164
+ type_for_activerecord_value(column_type.cast_type, column_nullability:)
164
165
  when ->(type) {
165
166
  defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid) &&
166
167
  ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Uuid === type
@@ -180,12 +181,25 @@ module Tapioca
180
181
  defined?(ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array) &&
181
182
  ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array === type
182
183
  }
183
- "T::Array[#{type_for_activerecord_value(column_type.subtype)}]"
184
+ "T::Array[#{type_for_activerecord_value(column_type.subtype, column_nullability:)}]"
184
185
  else
185
- ActiveModelTypeHelper.type_for(column_type)
186
+ as_non_nilable_if_persisted_and_not_nullable(
187
+ ActiveModelTypeHelper.type_for(column_type),
188
+ column_nullability: column_nullability,
189
+ )
186
190
  end
187
191
  end
188
192
 
193
+ sig { params(base_type: String, column_nullability: T::Boolean).returns(String) }
194
+ def as_non_nilable_if_persisted_and_not_nullable(base_type, column_nullability:)
195
+ # It's possible that when ActiveModel::Type::Value is used, the signature being reflected on in
196
+ # ActiveModelTypeHelper.type_for(type_value) may say the type can be nilable. However, if the type is
197
+ # persisted and the column is not nullable, we can assume it's not nilable.
198
+ return as_non_nilable_type(base_type) if @column_type_option.persisted? && !column_nullability
199
+
200
+ base_type
201
+ end
202
+
189
203
  sig { params(column_type: ActiveRecord::Enum::EnumType).returns(String) }
190
204
  def enum_setter_type(column_type)
191
205
  # In Rails < 7 this method is private. When support for that is dropped we can call the method directly
@@ -19,24 +19,24 @@ require "netrc"
19
19
  require "parallel"
20
20
  require "pathname"
21
21
  require "shellwords"
22
- require "spoom"
23
22
  require "tempfile"
24
23
  require "thor"
25
24
  require "yaml"
26
25
  require "yard-sorbet"
27
26
 
28
27
  require "tapioca/runtime/dynamic_mixin_compiler"
29
- require "tapioca/helpers/gem_helper"
30
-
31
- require "tapioca/helpers/git_attributes"
32
- require "tapioca/helpers/sorbet_helper"
33
- require "tapioca/helpers/rbi_helper"
34
28
  require "tapioca/sorbet_ext/backcompat_patches"
35
29
  require "tapioca/sorbet_ext/name_patch"
36
30
  require "tapioca/sorbet_ext/generic_name_patch"
37
31
  require "tapioca/sorbet_ext/proc_bind_patch"
38
32
  require "tapioca/runtime/generic_type_registry"
39
33
 
34
+ require "spoom"
35
+ require "tapioca/helpers/gem_helper"
36
+ require "tapioca/helpers/git_attributes"
37
+ require "tapioca/helpers/sorbet_helper"
38
+ require "tapioca/helpers/rbi_helper"
39
+
40
40
  require "tapioca/helpers/source_uri"
41
41
  require "tapioca/helpers/cli_helper"
42
42
  require "tapioca/helpers/config_helper"
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.15.0"
5
+ VERSION = "0.15.1"
6
6
  end
data/lib/tapioca.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require "sorbet-runtime"
5
+ require "rubygems/user_interaction"
5
6
 
6
7
  module Tapioca
7
8
  extend T::Sig
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapioca
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.15.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
8
8
  - Alan Wu
9
9
  - Alexandre Terrasa
10
10
  - Peter Zhu
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2024-06-27 00:00:00.000000000 Z
14
+ date: 2024-07-10 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -131,7 +131,7 @@ dependencies:
131
131
  - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
- description:
134
+ description:
135
135
  email:
136
136
  - ruby@shopify.com
137
137
  executables:
@@ -274,7 +274,7 @@ licenses:
274
274
  - MIT
275
275
  metadata:
276
276
  allowed_push_host: https://rubygems.org
277
- post_install_message:
277
+ post_install_message:
278
278
  rdoc_options: []
279
279
  require_paths:
280
280
  - lib
@@ -289,8 +289,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
289
289
  - !ruby/object:Gem::Version
290
290
  version: '0'
291
291
  requirements: []
292
- rubygems_version: 3.5.13
293
- signing_key:
292
+ rubygems_version: 3.5.14
293
+ signing_key:
294
294
  specification_version: 4
295
295
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard
296
296
  library