rails-on-sorbet 0.3.2 → 0.3.4

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: 933a41943fa0c0f4f3c967a1797fd1349e84aec021fa7aaa16f84daa947b04a3
4
- data.tar.gz: ad9925cfdff086e01e69b1738baca8ca6752435567e21c31a5829d926100addd
3
+ metadata.gz: f489d9f4fc449469fc2c648b63cce27cf7f6765cf119003037567414d8d82554
4
+ data.tar.gz: 16383eef9597808df2fe6e1b044ded34c3a3d1cbfcb26f0b029a30e0195171d1
5
5
  SHA512:
6
- metadata.gz: 693d8fe1a3d5d77200da6cbfa5a844075d48c3ec2dc65171bb528686f9dfaeb32d49992c2d3d08eee2359f4bd56748c70b38913a26a8f72f0d5c881ca041afd1
7
- data.tar.gz: 4065d3008fb38b9159c619c0eeda6ef7475aefffcbb6a22aca10137b754924e351cf6a6579b0639a18eef9e9ada1fa883af20fbd68c0de638c938341a4fa988e
6
+ metadata.gz: 3ad359e0b378b16ab174854a6a8d552d17b17eb82702c92e4fb06fb6919e42bc543141832c9d91b8be3faa9aa6dcd081e01060484fe4ffb80731d2542730431a
7
+ data.tar.gz: 3319c64c51f3002bed9d4016aef5c9d4d1216e508212b2eeee6d4190ee792aedbf470cc2caca698eb3dac232ded938fda41452d45a3076528ce98a73ee4b7bd5
data/CHANGELOG.md CHANGED
@@ -12,6 +12,21 @@ Add changes in new features here. Do not change the gem's version in pull/merge
12
12
  ### Changes
13
13
  -
14
14
 
15
+ ## [0.3.4] - 21.10.2025
16
+
17
+ [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.3...v0.3.4)
18
+
19
+ ### Changes
20
+ - Add `Map::Params`
21
+ - Require `TypedRelation` automatically
22
+
23
+ ## [0.3.3] - 20.10.2025
24
+
25
+ [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.2...v0.3.3)
26
+
27
+ ### Changes
28
+ - Fix tapioca compiler and subtyping for `TypedRelation`
29
+
15
30
  ## [0.3.2] - 20.10.2025
16
31
 
17
32
  [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.1...v0.3.2)
@@ -6,6 +6,9 @@ require 'active_support'
6
6
 
7
7
  module Map
8
8
  extend T::Generic
9
+
10
+ # Map type for API params.
11
+ Params = T.type_alias { Map[T.any(String, Symbol), T.untyped] }
9
12
  end
10
13
 
11
14
  def Map(val) = val # rubocop:disable Style/TopLevelMethodDefinition,Naming/MethodName
@@ -54,5 +54,6 @@ module TypedAssociation
54
54
 
55
55
  module CollectionProxy
56
56
  extend T::Generic
57
+ include TypedRelation
57
58
  end
58
59
  end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module On
5
5
  module Sorbet
6
- VERSION = '0.3.2'
6
+ VERSION = '0.3.4'
7
7
  end
8
8
  end
9
9
  end
@@ -16,3 +16,4 @@ require_relative 'sorbet/alias_association'
16
16
  require_relative 'sorbet/current_attributes'
17
17
  require_relative 'sorbet/map'
18
18
  require_relative 'sorbet/timelike'
19
+ require_relative 'sorbet/typed_relation'
@@ -20,26 +20,29 @@ module Tapioca
20
20
  #: -> void
21
21
  def decorate
22
22
  root.create_path(constant) do |klass|
23
- private_relation = klass.create_class('PrivateRelation')
23
+ private_relation = klass.create_class('PrivateRelation', superclass_name: '::ActiveRecord::Relation')
24
24
  private_relation.create_include('::TypedRelation')
25
25
 
26
- private_relation_group_chain = klass.create_class('PrivateRelationGroupChain')
26
+ private_relation_group_chain = klass.create_class('PrivateRelationGroupChain',
27
+ superclass_name: 'PrivateRelation',)
27
28
  private_relation_group_chain.create_include('::TypedRelation::GroupChain')
28
29
 
29
- private_relation_where_chain = klass.create_class('PrivateRelationWhereChain')
30
+ private_relation_where_chain = klass.create_class('PrivateRelationWhereChain', superclass_name: '::ActiveRecord::QueryMethods::WhereChain')
30
31
  private_relation_where_chain.create_include('::TypedRelation::WhereChain')
31
32
 
32
33
 
33
- private_association_relation = klass.create_class('PrivateAssociationRelation')
34
+ private_association_relation = klass.create_class('PrivateAssociationRelation', superclass_name: '::ActiveRecord::AssociationRelation')
34
35
  private_association_relation.create_include('::TypedAssociation::Relation')
35
36
 
36
- private_relation_group_chain = klass.create_class('PrivateAssociationRelationGroupChain')
37
+ private_relation_group_chain = klass.create_class('PrivateAssociationRelationGroupChain',
38
+ superclass_name: 'PrivateAssociationRelation',)
37
39
  private_relation_group_chain.create_include('::TypedAssociation::Relation::GroupChain')
38
40
 
39
- private_relation_where_chain = klass.create_class('PrivateAssociationRelationWhereChain')
41
+ private_relation_where_chain = klass.create_class('PrivateAssociationRelationWhereChain',
42
+ superclass_name: '::ActiveRecord::QueryMethods::WhereChain',)
40
43
  private_relation_where_chain.create_include('::TypedAssociation::Relation::WhereChain')
41
44
 
42
- private_collection_proxy = klass.create_class('PrivateCollectionProxy')
45
+ private_collection_proxy = klass.create_class('PrivateCollectionProxy', superclass_name: '::ActiveRecord::Associations::CollectionProxy')
43
46
  private_collection_proxy.create_include('::TypedAssociation::CollectionProxy')
44
47
  end
45
48
  end
data/rbi/map.rbi CHANGED
@@ -4,6 +4,32 @@
4
4
  #: (ActionController::Parameters | ActiveSupport::HashWithIndifferentAccess) -> Map[String | Symbol, untyped]
5
5
  def Map(val); end
6
6
 
7
+ # `Map` represents a hash-like object
8
+ # Use the `Map` type in a signature.
9
+ #
10
+ # #: (Map[Symbol | String, Integer]) -> void
11
+ # def foo(m)
12
+ # m["foo"] #=> Integer?
13
+ # end
14
+ #
15
+ # hash = { "foo" => 4 } #: Hash[String, Integer]
16
+ # m = Map(hash) #=> Map[Symbol | String, Integer]
17
+ # foo(m) # OK
18
+ #
19
+ # hash = { "foo" => 4 }.with_indifferent_access # => ActiveSupport::HashWithIndifferentAccess
20
+ # m = Map(hash) #=> Map[Symbol | String, untyped]
21
+ # foo(m) # OK
22
+ #
23
+ # params = ActionController::Parameters.new # => ActionController::Parameters
24
+ # m = Map(params) #=> Map[Symbol | String, untyped]
25
+ # foo(m) # OK
26
+ #
27
+ # Cast a `Hash`, `ActionController::Parameters` or `ActiveSupport::HashWithIndifferentAccess`
28
+ # to a `Map`. The `Map` type defines common methods shared between these hash-like types.
29
+ #
30
+ # Due to current Sorbet limitations, hash-like types cannot directly implement the `Map` interface.
31
+ # The `Map` method provides a way to cast between hash-like types and `Map` to enable type-safe usage.
32
+ #
7
33
  # @requires_ancestor: Object
8
34
  # @abstract
9
35
  #: [out K, out V]
@@ -417,6 +417,8 @@ module TypedCommonRelationMethods
417
417
  # END CommonRelationMethods
418
418
  end
419
419
 
420
+ # Represents a typed `ActiveRecord::Relation`.
421
+ #
420
422
  # @abstract
421
423
  module TypedRelation
422
424
  extend T::Generic
@@ -884,9 +886,12 @@ module TypedAssociation
884
886
  end
885
887
  end
886
888
 
889
+ # Represents a typed `ActiveRecord::Associations::CollectionProxy`
890
+ #
887
891
  # @abstract
888
892
  module CollectionProxy
889
893
  extend T::Generic
894
+ include TypedRelation
890
895
  include TypedCommonRelationMethods
891
896
  include TypedGeneratedAssociationRelationMethods
892
897
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-on-sorbet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak