tapioca 0.11.14 → 0.11.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52388d4c8afe40a2b6807e54bf1dd09701cb016ca1fed7ce5d3a691c3f93e0e5
4
- data.tar.gz: 18550aa93626f63257b387154585dc2ae9e74c5aa17c7d4e2b82702bf5ce5b2b
3
+ metadata.gz: 4f089694c098df2b42355826c7622448368a7f766bd44de3cd2ece4242ebc0fa
4
+ data.tar.gz: 0140650be1098b51150d5a74fac1f349e9a8da6400fcc5ad3ed1e0da84fb7a91
5
5
  SHA512:
6
- metadata.gz: c0be5c5d8108519bbda67d2498ff032273ad855a45c464a5a0acf0780412e7f4d3ee706322ef287fd2882ee0083f3c3fe1ab67611a16a6f45f5aa5a7aeb1a709
7
- data.tar.gz: 6a87ab2319905c976cfb0b6a004c12d613a9200269268c6c452f8f7ba9175a1b7fd29c5d32de945a04614aff1de037463ad3c0fd090f883770a7f72d7f2f1476
6
+ metadata.gz: 95bbca796e14a6af94dbbaa9f15a3cd15c46d414472b03385ab7ff6b8ab495ba885ee362e7349bbdc7ed0c60639d22fb2db52e0d901faab582fca96a93dfd408
7
+ data.tar.gz: 179e7b4ef4c30819d7a3e1c3cb856b800ffc17c63d20419341002b4273b56c9cec2d9d06e03d28678275ac2c9e8e82030f7cfb2d8f5bf4bdc99ead5e361d001a
@@ -72,9 +72,9 @@ module Tapioca
72
72
  def attribute_methods_for_constant
73
73
  patterns = if constant.respond_to?(:attribute_method_patterns)
74
74
  # https://github.com/rails/rails/pull/44367
75
- T.unsafe(constant).attribute_method_patterns
75
+ constant.attribute_method_patterns
76
76
  else
77
- constant.attribute_method_matchers
77
+ T.unsafe(constant).attribute_method_matchers
78
78
  end
79
79
  patterns.flat_map do |pattern|
80
80
  constant.attribute_types.filter_map do |name, value|
@@ -101,8 +101,13 @@ module Tapioca
101
101
  HANDLED_METHOD_TARGETS.include?(target.to_s)
102
102
  end
103
103
 
104
- sig { params(attribute_type_value: ::ActiveModel::Type::Value).returns(::String) }
104
+ sig { params(attribute_type_value: T.untyped).returns(::String) }
105
105
  def type_for(attribute_type_value)
106
+ # This guarantees that the type will remain as T.untyped for attributes in the following form:
107
+ # attribute :name
108
+ # This is because for a generic attribute with no specified type, ActiveModel::Type::Value.new is returned
109
+ return "T.untyped" if attribute_type_value.instance_of?(ActiveModel::Type::Value)
110
+
106
111
  type = case attribute_type_value
107
112
  when ActiveModel::Type::Boolean
108
113
  "T::Boolean"
@@ -119,8 +124,7 @@ module Tapioca
119
124
  when ActiveModel::Type::String
120
125
  "::String"
121
126
  else
122
- # we don't want untyped to be wrapped by T.nilable, so just return early
123
- return "T.untyped"
127
+ attribute_type_value.class.name.to_s
124
128
  end
125
129
 
126
130
  as_nilable_type(type)
@@ -108,6 +108,11 @@ module Tapioca
108
108
  def decorate
109
109
  return unless constant.table_exists?
110
110
 
111
+ # We need to call this to ensure that some attribute aliases are defined, e.g.
112
+ # `id_value` as an alias for `id`.
113
+ # I think this is a regression on Rails 7.1, but we are where we are.
114
+ constant.define_attribute_methods
115
+
111
116
  root.create_path(constant) do |model|
112
117
  model.create_module(AttributeMethodsModuleName) do |mod|
113
118
  (constant.attribute_names + ["id"]).uniq.each do |attribute_name|
@@ -119,9 +124,9 @@ module Tapioca
119
124
  column_name = column_name.to_s
120
125
  patterns = if constant.respond_to?(:attribute_method_patterns)
121
126
  # https://github.com/rails/rails/pull/44367
122
- T.unsafe(constant).attribute_method_patterns
127
+ constant.attribute_method_patterns
123
128
  else
124
- constant.attribute_method_matchers
129
+ T.unsafe(constant).attribute_method_matchers
125
130
  end
126
131
  new_method_names = patterns.map { |m| m.method_name(attribute_name) }
127
132
  old_method_names = patterns.map { |m| m.method_name(column_name) }
@@ -110,11 +110,10 @@ module Tapioca
110
110
  return_type: "ActiveSupport::StringInquirer",
111
111
  )
112
112
 
113
- return_type = sorbet_supports?(:generic_class) ? "T::Class[T.anything]" : "Class"
114
113
  mod.create_method(
115
114
  "#{role}_class",
116
115
  parameters: [],
117
- return_type: return_type,
116
+ return_type: "T::Class[T.anything]",
118
117
  )
119
118
 
120
119
  mod.create_method(
@@ -271,9 +271,7 @@ module Tapioca
271
271
 
272
272
  klass = class_of(value)
273
273
 
274
- klass_name = if klass == ObjectSpace::WeakMap
275
- sorbet_supports?(:non_generic_weak_map) ? "ObjectSpace::WeakMap" : "ObjectSpace::WeakMap[T.untyped]"
276
- elsif T::Generic === klass
274
+ klass_name = if T::Generic === klass
277
275
  generic_name_of(klass)
278
276
  else
279
277
  name_of(klass)
@@ -24,8 +24,6 @@ module Tapioca
24
24
  FEATURE_REQUIREMENTS = T.let(
25
25
  {
26
26
  # feature_name: ::Gem::Requirement.new(">= ___"), # https://github.com/sorbet/sorbet/pull/___
27
- non_generic_weak_map: ::Gem::Requirement.new(">= 0.5.10587"), # https://github.com/sorbet/sorbet/pull/6610
28
- generic_class: ::Gem::Requirement.new(">= 0.5.10820"), # https://github.com/sorbet/sorbet/pull/6781
29
27
  }.freeze,
30
28
  T::Hash[Symbol, ::Gem::Requirement],
31
29
  )
@@ -32,7 +32,6 @@ require "tapioca/helpers/git_attributes"
32
32
  require "tapioca/helpers/sorbet_helper"
33
33
  require "tapioca/helpers/rbi_helper"
34
34
  require "tapioca/sorbet_ext/backcompat_patches"
35
- require "tapioca/sorbet_ext/fixed_hash_patch"
36
35
  require "tapioca/sorbet_ext/name_patch"
37
36
  require "tapioca/sorbet_ext/generic_name_patch"
38
37
  require "tapioca/sorbet_ext/proc_bind_patch"
@@ -1,24 +1,6 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- unless defined?(T.anything)
5
- module T
6
- class << self
7
- def anything
8
- T.untyped
9
- end
10
- end
11
- end
12
- end
4
+ # This file contains patches to make Tapioca work with older versions of Sorbet.
13
5
 
14
- unless defined?(T::Class)
15
- module T
16
- module Class
17
- class << self
18
- def [](type)
19
- T.untyped
20
- end
21
- end
22
- end
23
- end
24
- end
6
+ # NOTE: If there is currently no need for any patches, this file will be empty.
@@ -18,32 +18,26 @@ module T
18
18
  Tapioca::Runtime::GenericTypeRegistry.register_type(constant, types)
19
19
  end
20
20
 
21
- def type_member(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
21
+ def type_member(variance = :invariant, &bounds_proc)
22
22
  # `T::Generic#type_member` just instantiates a `T::Type::TypeMember` instance and returns it.
23
23
  # We use that when registering the type member and then later return it from this method.
24
24
  Tapioca::TypeVariableModule.new(
25
25
  T.cast(self, Module),
26
26
  Tapioca::TypeVariableModule::Type::Member,
27
27
  variance,
28
- fixed,
29
- lower,
30
- upper,
31
28
  bounds_proc,
32
29
  ).tap do |type_variable|
33
30
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
34
31
  end
35
32
  end
36
33
 
37
- def type_template(variance = :invariant, fixed: nil, lower: nil, upper: nil, &bounds_proc)
34
+ def type_template(variance = :invariant, &bounds_proc)
38
35
  # `T::Generic#type_template` just instantiates a `T::Type::TypeTemplate` instance and returns it.
39
36
  # We use that when registering the type template and then later return it from this method.
40
37
  Tapioca::TypeVariableModule.new(
41
38
  T.cast(self, Module),
42
39
  Tapioca::TypeVariableModule::Type::Template,
43
40
  variance,
44
- fixed,
45
- lower,
46
- upper,
47
41
  bounds_proc,
48
42
  ).tap do |type_variable|
49
43
  Tapioca::Runtime::GenericTypeRegistry.register_type_variable(self, type_variable)
@@ -57,9 +51,6 @@ module T
57
51
  T.cast(self, Module),
58
52
  Tapioca::TypeVariableModule::Type::HasAttachedClass,
59
53
  variance,
60
- nil,
61
- nil,
62
- nil,
63
54
  bounds_proc,
64
55
  ),
65
56
  )
@@ -93,29 +84,9 @@ module T
93
84
  end
94
85
 
95
86
  module Utils
96
- # This duplication is required to preserve backwards compatibility with sorbet-runtime versions prior to the
97
- # introduction of the `Private` module in https://github.com/sorbet/sorbet/pull/6559.
98
- if defined?(T::Utils::Private)
99
- module Private
100
- module PrivateCoercePatch
101
- def coerce_and_check_module_types(val, check_val, check_module_type)
102
- if val.is_a?(Tapioca::TypeVariableModule)
103
- val.coerce_to_type_variable
104
- elsif val.respond_to?(:__tapioca_override_type)
105
- val.__tapioca_override_type
106
- else
107
- super
108
- end
109
- end
110
- end
111
-
112
- class << self
113
- prepend(PrivateCoercePatch)
114
- end
115
- end
116
- else
117
- module CoercePatch
118
- def coerce(val)
87
+ module Private
88
+ module PrivateCoercePatch
89
+ def coerce_and_check_module_types(val, check_val, check_module_type)
119
90
  if val.is_a?(Tapioca::TypeVariableModule)
120
91
  val.coerce_to_type_variable
121
92
  elsif val.respond_to?(:__tapioca_override_type)
@@ -127,7 +98,7 @@ module T
127
98
  end
128
99
 
129
100
  class << self
130
- prepend(CoercePatch)
101
+ prepend(PrivateCoercePatch)
131
102
  end
132
103
  end
133
104
  end
@@ -159,35 +130,27 @@ module Tapioca
159
130
  end
160
131
  end
161
132
 
133
+ DEFAULT_BOUNDS_PROC = T.let(-> { {} }, T.proc.returns(T::Hash[Symbol, T.untyped]))
134
+
162
135
  sig { returns(Type) }
163
136
  attr_reader :type
164
137
 
165
- # rubocop:disable Metrics/ParameterLists
166
138
  sig do
167
139
  params(
168
140
  context: Module,
169
141
  type: Type,
170
142
  variance: Symbol,
171
- fixed: T.untyped,
172
- lower: T.untyped,
173
- upper: T.untyped,
174
143
  bounds_proc: T.nilable(T.proc.returns(T::Hash[Symbol, T.untyped])),
175
144
  ).void
176
145
  end
177
- def initialize(context, type, variance, fixed, lower, upper, bounds_proc)
146
+ def initialize(context, type, variance, bounds_proc)
178
147
  @context = context
179
148
  @type = type
180
149
  @variance = variance
181
- @bounds_proc = if bounds_proc
182
- bounds_proc
183
- else
184
- build_bounds_proc(fixed, lower, upper)
185
- end
150
+ @bounds_proc = bounds_proc || DEFAULT_BOUNDS_PROC
186
151
 
187
152
  super()
188
153
  end
189
- # rubocop:enable Metrics/ParameterLists
190
-
191
154
  sig { returns(T.nilable(String)) }
192
155
  def name
193
156
  constant_name = super
@@ -221,19 +184,6 @@ module Tapioca
221
184
 
222
185
  private
223
186
 
224
- sig do
225
- params(fixed: T.untyped, lower: T.untyped, upper: T.untyped)
226
- .returns(T.proc.returns(T::Hash[Symbol, T.untyped]))
227
- end
228
- def build_bounds_proc(fixed, lower, upper)
229
- bounds = {}
230
- bounds[:fixed] = fixed unless fixed.nil?
231
- bounds[:lower] = lower unless lower.nil?
232
- bounds[:upper] = upper unless upper.nil?
233
-
234
- -> { bounds }
235
- end
236
-
237
187
  sig { returns(T::Hash[Symbol, T.untyped]) }
238
188
  def bounds
239
189
  @bounds ||= @bounds_proc.call
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Tapioca
5
- VERSION = "0.11.14"
5
+ VERSION = "0.11.15"
6
6
  end
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.11.14
4
+ version: 0.11.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ufuk Kayserilioglu
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2023-12-18 00:00:00.000000000 Z
14
+ date: 2024-01-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -81,14 +81,14 @@ dependencies:
81
81
  requirements:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 0.5.10187
84
+ version: 0.5.10820
85
85
  type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ">="
90
90
  - !ruby/object:Gem::Version
91
- version: 0.5.10187
91
+ version: 0.5.10820
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: spoom
94
94
  requirement: !ruby/object:Gem::Requirement
@@ -265,7 +265,6 @@ files:
265
265
  - lib/tapioca/runtime/trackers/required_ancestor.rb
266
266
  - lib/tapioca/runtime/trackers/tracker.rb
267
267
  - lib/tapioca/sorbet_ext/backcompat_patches.rb
268
- - lib/tapioca/sorbet_ext/fixed_hash_patch.rb
269
268
  - lib/tapioca/sorbet_ext/generic_name_patch.rb
270
269
  - lib/tapioca/sorbet_ext/name_patch.rb
271
270
  - lib/tapioca/sorbet_ext/proc_bind_patch.rb
@@ -293,7 +292,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
292
  - !ruby/object:Gem::Version
294
293
  version: '0'
295
294
  requirements: []
296
- rubygems_version: 3.4.22
295
+ rubygems_version: 3.5.4
297
296
  signing_key:
298
297
  specification_version: 4
299
298
  summary: A Ruby Interface file generator for gems, core types and the Ruby standard
@@ -1,20 +0,0 @@
1
- # typed: true
2
- # frozen_string_literal: true
3
-
4
- module T
5
- module Types
6
- class FixedHash
7
- def name
8
- entries = @types.map do |(k, v)|
9
- if Symbol === k && ":#{k}" == k.inspect
10
- "#{k}: #{v}"
11
- else
12
- "#{k.inspect} => #{v}"
13
- end
14
- end
15
-
16
- "{#{entries.join(", ")}}"
17
- end
18
- end
19
- end
20
- end