rails-on-sorbet 0.3.3 → 0.3.5

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: d255de247b08a136edde26f15049767590f2e303a78e2551df4ef8998ab84512
4
- data.tar.gz: 1d6c912134b2345bd3d6e537b99ab1d89f68f6b6c1ad60f9ea9556a8c025ff3f
3
+ metadata.gz: 20f5398f4347bd7235077b77dcbce2916b0ec30001eab8ce4da12d290322515d
4
+ data.tar.gz: 59caf094a17595e0e6c4d5ea26b870098dc0d7b9a06d8f8edcb55fa9aeecd033
5
5
  SHA512:
6
- metadata.gz: 7bb596b03ee49d914a6d555eb646b1074357ea2368d24b2dd5a424ce3265de740ab44cbbd7191095cb39622e6991b77e6affa21762a3f5dad6dba078778fea27
7
- data.tar.gz: da155d5a8360f016a854a2d9f9ff9b2ee28b60a83f397d6593773730ff4186ecd4af5ed39ca5966f00317862e95235f4479c6ce062ba41cbde709503560ae178
6
+ metadata.gz: e389aaf40e8f111aec4c8d2bbdf6cc7e17af5d70ebcefd18d65b5876339cc0223c8e6c2dbec086dcb4840d2fcd75fa9a0092dfd8a32be46d1ae0932a03daed54
7
+ data.tar.gz: 4a54cd049174abcb664f80e8c22fdda7b18b62234f29d63f35cb8c285c79677a986a01a59190cab94a53a884e9724513bbdeaabeb258083e4a0f06429107cbe0
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.5] - 21.10.2025
16
+
17
+ [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.4...v0.3.5)
18
+
19
+ ### Changes
20
+ - Fix `TypedRelation` RBI and tapioca compiler
21
+
22
+ ## [0.3.4] - 21.10.2025
23
+
24
+ [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.3...v0.3.4)
25
+
26
+ ### Changes
27
+ - Add `Map::Params`
28
+ - Require `TypedRelation` automatically
29
+
15
30
  ## [0.3.3] - 20.10.2025
16
31
 
17
32
  [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.3.2...v0.3.3)
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module On
5
5
  module Sorbet
6
- VERSION = '0.3.3'
6
+ VERSION = '0.3.5'
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'
@@ -22,28 +22,34 @@ module Tapioca
22
22
  root.create_path(constant) do |klass|
23
23
  private_relation = klass.create_class('PrivateRelation', superclass_name: '::ActiveRecord::Relation')
24
24
  private_relation.create_include('::TypedRelation')
25
+ private_relation.create_type_variable('Elem', type: 'type_member', variance: :out)
25
26
 
26
27
  private_relation_group_chain = klass.create_class('PrivateRelationGroupChain',
27
28
  superclass_name: 'PrivateRelation',)
28
29
  private_relation_group_chain.create_include('::TypedRelation::GroupChain')
30
+ private_relation_group_chain.create_type_variable('Elem', type: 'type_member', variance: :out)
29
31
 
30
32
  private_relation_where_chain = klass.create_class('PrivateRelationWhereChain', superclass_name: '::ActiveRecord::QueryMethods::WhereChain')
31
33
  private_relation_where_chain.create_include('::TypedRelation::WhereChain')
32
-
34
+ private_relation_where_chain.create_type_variable('Elem', type: 'type_member', variance: :out)
33
35
 
34
36
  private_association_relation = klass.create_class('PrivateAssociationRelation', superclass_name: '::ActiveRecord::AssociationRelation')
35
37
  private_association_relation.create_include('::TypedAssociation::Relation')
38
+ private_association_relation.create_type_variable('Elem', type: 'type_member', variance: :out)
36
39
 
37
40
  private_relation_group_chain = klass.create_class('PrivateAssociationRelationGroupChain',
38
41
  superclass_name: 'PrivateAssociationRelation',)
39
42
  private_relation_group_chain.create_include('::TypedAssociation::Relation::GroupChain')
43
+ private_relation_group_chain.create_type_variable('Elem', type: 'type_member', variance: :out)
40
44
 
41
45
  private_relation_where_chain = klass.create_class('PrivateAssociationRelationWhereChain',
42
46
  superclass_name: '::ActiveRecord::QueryMethods::WhereChain',)
43
47
  private_relation_where_chain.create_include('::TypedAssociation::Relation::WhereChain')
48
+ private_relation_where_chain.create_type_variable('Elem', type: 'type_member', variance: :out)
44
49
 
45
50
  private_collection_proxy = klass.create_class('PrivateCollectionProxy', superclass_name: '::ActiveRecord::Associations::CollectionProxy')
46
51
  private_collection_proxy.create_include('::TypedAssociation::CollectionProxy')
52
+ private_collection_proxy.create_type_variable('Elem', type: 'type_member', variance: :out)
47
53
  end
48
54
  end
49
55
 
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,15 +417,17 @@ 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
423
425
  Elem = type_member(:out)
424
426
 
425
427
  class << self
426
- #: (ActiveRecord::Relation) -> GroupChain[untyped]
428
+ #: (ActiveRecord::Relation) -> TypedRelation::GroupChain[untyped]
427
429
  def GroupChain(val); end
428
- #: (ActiveRecord::QueryMethods::WhereChain) -> WhereChain[untyped]
430
+ #: (ActiveRecord::QueryMethods::WhereChain) -> TypedRelation::WhereChain[untyped]
429
431
  def WhereChain(val); end
430
432
  end
431
433
 
@@ -805,7 +807,7 @@ end
805
807
 
806
808
  module TypedAssociation
807
809
  class << self
808
- #: (::ActiveRecord::Relation) -> Relation[untyped]
810
+ #: (::ActiveRecord::Relation) -> TypedAssociation::Relation[untyped]
809
811
  def Relation(val); end
810
812
  #: (::ActiveRecord::Associations::CollectionProxy) -> CollectionProxy[untyped]
811
813
  def CollectionProxy(val); end
@@ -820,9 +822,9 @@ module TypedAssociation
820
822
  Elem = type_member(:out)
821
823
 
822
824
  class << self
823
- #: (ActiveRecord::Relation) -> GroupChain[untyped]
825
+ #: (ActiveRecord::Relation) -> TypedAssociation::Relation::GroupChain[untyped]
824
826
  def GroupChain(val); end
825
- #: (ActiveRecord::QueryMethods::WhereChain) -> WhereChain[untyped]
827
+ #: (ActiveRecord::QueryMethods::WhereChain) -> TypedAssociation::Relation::WhereChain[untyped]
826
828
  def WhereChain(val); end
827
829
  end
828
830
 
@@ -831,20 +833,20 @@ module TypedAssociation
831
833
  extend T::Generic
832
834
  Elem = type_member(:out)
833
835
 
834
- sig { abstract.params(args: T.untyped).returns(Relation[Elem]) }
836
+ sig { abstract.params(args: T.untyped).returns(TypedAssociation::Relation[Elem]) }
835
837
  def associated(*args); end
836
838
 
837
- sig { abstract.params(args: T.untyped).returns(Relation[Elem]) }
839
+ sig { abstract.params(args: T.untyped).returns(TypedAssociation::Relation[Elem]) }
838
840
  def missing(*args); end
839
841
 
840
- sig { abstract.params(opts: T.untyped, rest: T.untyped).returns(Relation[Elem]) }
842
+ sig { abstract.params(opts: T.untyped, rest: T.untyped).returns(TypedAssociation::Relation[Elem]) }
841
843
  def not(opts, *rest); end
842
844
  end
843
845
 
844
846
  # @abstract
845
847
  module GroupChain
846
848
  extend T::Generic
847
- include Relation
849
+ include TypedAssociation::Relation
848
850
 
849
851
  Elem = type_member(:out)
850
852
 
@@ -884,6 +886,8 @@ 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
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.3
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak