rails-on-sorbet 0.1.1 → 0.2.0

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: 057657277f463d4d5784ead1bc900e19797c5bea05a320a5b66b1fe45472768b
4
- data.tar.gz: 806b3922d612631f5f6ae5b5f3570fbafe5ba60e2446b95be7c6b495eb0d7f29
3
+ metadata.gz: 829640700a30c44c134bd05f675cfbf4eb45f43c78d90cd87f52a25f1a8983bd
4
+ data.tar.gz: 7f50468584b1edc3c2d419c91758bb2f731468bcff1f22642dd81000484f7c77
5
5
  SHA512:
6
- metadata.gz: 4032afbde300e87f28f6463b7e86036fad5f043d05d3f886be0e942121492b928598e75c381d851893913a1afd6ef6a80284eb51483debbef769f6db86ebfb7d
7
- data.tar.gz: 4f4b029c8dc13209457c36e25076f867fc6c607bbf50eb6a77ae3a39fd500841e0986b7f0e2951dc64ccb571c9b6948dae197df98c99a32f3bc730fdba4def50
6
+ metadata.gz: b98bee4beaaaf076fa5380d796fd80fa6f257f67a1ad6e52fb38264cc696b12803b9ac0a5020024372207a1c2e8627d684ab997aebd62f5dc3ed9238d55d495e
7
+ data.tar.gz: cd792edc2489914c401f3832ef28b7a69ebe54b15a28ae3ac5fe7bcef24759715b5958e4ae106d37562b6dbf211e542dcc0d8ec4b9a07f1b94b3ada12dd34522
data/CHANGELOG.md CHANGED
@@ -12,6 +12,14 @@ 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.2.0] - 18.09.2025
16
+
17
+ [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.1.1...v0.2.0)
18
+
19
+ ### Changes
20
+ - Change `Rails::On::Sorbet::CurrentAttributes` from a module to a class
21
+ - Favour using `Rails::On::Sorbet::CurrentAttributes` instead of `ActiveSupport::CurrentAttributes`
22
+
15
23
  ## [0.1.1] - 18.09.2025
16
24
 
17
25
  [Diff](https://github.com/espago/rails-on-sorbet/compare/v0.1.0...v0.1.1)
data/README.md CHANGED
@@ -16,6 +16,17 @@ If bundler is not being used to manage dependencies, install the gem by executin
16
16
  gem install rails-on-sorbet
17
17
  ```
18
18
 
19
+ It is recommended to disable strict typechecking for this gem's RBI files
20
+ generated by tapioca.
21
+
22
+ This can be done by adding these lines to `sorbet/tapioca/config.yml`:
23
+
24
+ ```yml
25
+ gem:
26
+ typed_overrides:
27
+ rails-on-sorbet: "false"
28
+ ```
29
+
19
30
  ## Usage
20
31
 
21
32
  This gem adds additional signatures to Rails types and builtin Ruby types that
@@ -90,15 +101,17 @@ Example:
90
101
  f.owner == f.user #=> true
91
102
  ```
92
103
 
93
- ### ActiveSupport::CurrentAttributes
104
+ ### Rails::On::Sorbet::CurrentAttributes
105
+
106
+ This is a subclass of `ActiveSupport::CurrentAttributes` with tapioca/sorbet support.
94
107
 
95
- New optional keyword arguments have been added to `ActiveSupport::CurrentAttributes::attribute`:
108
+ New optional keyword arguments have been added to `attribute`:
96
109
  - `type`: the sorbet type of the getter/setter
97
110
  - `doc`: a docstring whose content will be used to generate a comment above the rbi signature created by tapioca
98
111
 
99
112
  Example:
100
113
  ```rb
101
- class Current < ActiveSupport::CurrentAttributes
114
+ class Current < Rails::On::Sorbet::CurrentAttributes
102
115
  attribute :session_counter, type: T.nilable(Integer), doc: <<~DOC
103
116
  A counter that gets incremented when a new session is created.
104
117
  DOC
@@ -1,11 +1,11 @@
1
1
  # typed: false
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'active_support'
5
+
4
6
  module Rails::On::Sorbet
5
7
  # Shim for ActiveSupport::CurrentAttributes to support sorbet
6
- #
7
- # @requires_ancestor: singleton(ActiveSupport::CurrentAttributes)
8
- module CurrentAttributes
8
+ class CurrentAttributes < ActiveSupport::CurrentAttributes
9
9
  # Holds the data of a single attribute definition
10
10
  class Attribute
11
11
  #: Symbol
@@ -25,29 +25,23 @@ module Rails::On::Sorbet
25
25
  end
26
26
  end
27
27
 
28
- # Get a map with all defined attributes and their types
29
- #
30
- #: -> Hash[Symbol, Attribute]
31
- def attribute_map
32
- @attribute_map ||= {}
33
- end
28
+ class << self
29
+ # Get a map with all defined attributes and their types
30
+ #
31
+ #: -> Hash[Symbol, Attribute]
32
+ def attribute_map
33
+ @attribute_map ||= {}
34
+ end
34
35
 
35
- # Declare a new attribute with a sorbet type
36
- #
37
- #: (*Symbol, ?type: untyped, ?doc: String?, ?default: untyped) -> void
38
- def attribute(*names, type: nil, doc: nil, default: ::ActiveSupport::CurrentAttributes::NOT_SET)
39
- names.each do |name|
40
- attribute_map[name] = Attribute.new(name, type, doc)
36
+ # Declare a new attribute with a sorbet type
37
+ #
38
+ #: (*Symbol, ?type: untyped, ?doc: String?, ?default: untyped) -> void
39
+ def attribute(*names, type: nil, doc: nil, default: ::ActiveSupport::CurrentAttributes::NOT_SET)
40
+ names.each do |name|
41
+ attribute_map[name] = Attribute.new(name, type, doc)
42
+ end
43
+ super(*names, default: default)
41
44
  end
42
- super(*names, default: default)
43
45
  end
44
46
  end
45
47
  end
46
-
47
- require 'active_support'
48
-
49
- module ActiveSupport
50
- class CurrentAttributes # rubocop:disable Style/StaticClass
51
- extend Rails::On::Sorbet::CurrentAttributes
52
- end
53
- end
@@ -9,13 +9,3 @@ module Map
9
9
  end
10
10
 
11
11
  def Map(val) = val # rubocop:disable Style/TopLevelMethodDefinition,Naming/MethodName
12
-
13
- #: [K = String, V = untyped]
14
- class ActionController::Parameters
15
- include Map
16
- end
17
-
18
- #: [K = String, V = untyped]
19
- class ActiveSupport::HashWithIndifferentAccess
20
- include Map
21
- end
@@ -3,7 +3,7 @@
3
3
  module Rails
4
4
  module On
5
5
  module Sorbet
6
- VERSION = '0.1.1'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Tapioca
5
5
  module Compilers
6
- #: [ConstantType = Class & ::Rails::On::Sorbet::CurrentAttributes]
6
+ #: [ConstantType = singleton(::Rails::On::Sorbet::CurrentAttributes)]
7
7
  class RailsOnSorbetCurrentAttributes < Tapioca::Dsl::Compiler
8
8
 
9
9
  class << self
@@ -11,7 +11,7 @@ module Tapioca
11
11
  #: -> Enumerable[Module]
12
12
  def gather_constants
13
13
  all_classes.select do |klass|
14
- klass.singleton_class < ::Rails::On::Sorbet::CurrentAttributes
14
+ klass < ::Rails::On::Sorbet::CurrentAttributes
15
15
  end
16
16
  end
17
17
  end
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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Drewniak