sorbet_typed-props 1.0.4 → 1.1.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: 2a592ea589b670f5f15dc36a4b00d0d5e659190b9a442be66acb9007c6f0e4f5
4
- data.tar.gz: b0ac757e59aaeb2abc27b98b96dbc2fcfff6409c450e248923c021c341acc869
3
+ metadata.gz: 2c457e7b60e68c291d4b327324fb3a252f8eda2b2aff2387d4673f351cb3b7fb
4
+ data.tar.gz: e39071b28288af5469881d35b5872997b988c63b4161ca75561ca8e58f178ef6
5
5
  SHA512:
6
- metadata.gz: ce94fa3dcd6bb3dcaf18272236a4c2be10681a461e6482c0730a5242d4e47b50f202797fa179d04fd33e51f5e6b01de9f42be9ef184d1f914b334ff4a5836b34
7
- data.tar.gz: 90ed51e7e0b3209c005e4c6222c7a84c24414e03dab4f98ff248c737c27668e88d9fa5459951b33568a6ae5d61df9ff2ea0b77db37095801be9b68bba5bc8560
6
+ metadata.gz: 907229513f1e616e0e7b5421485fcb02e20c62d8ae053615fbfafbbfca28c6afa63fedc5dd980c6e7e30f1a697eb38402a1b76944359c8b1038c7db1b685e388
7
+ data.tar.gz: 0e7eca8bf03774d1504603435c581b9cf40940bd04fcf602e310a7fa105cc61b34ac63d09d6f2330fb5a13f64572c057211400308042aa816a8b9eb9d2a35ee5
data/.cz.yaml CHANGED
@@ -15,7 +15,7 @@ commitizen:
15
15
  - mise run format
16
16
  tag_format: v$version
17
17
  update_changelog_on_bump: true
18
- version: 1.0.4
18
+ version: 1.1.0
19
19
  version_files:
20
20
  - lib/sorbet_typed/props/version.rb
21
21
  version_scheme: semver2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## v1.1.0 (2025-11-22)
2
+
3
+ ### Feat
4
+
5
+ - add `post_props_initialize` hook to extend initializer logic
6
+
7
+ ### Fix
8
+
9
+ - **deps**: update sorbet to v0.6.12784
10
+ - **deps**: update sorbet to v0.6.12783
11
+
1
12
  ## v1.0.4 (2025-11-20)
2
13
 
3
14
  ### Fix
data/README.md CHANGED
@@ -17,6 +17,8 @@ in parallel).
17
17
  - [Installation](#installation)
18
18
  - [Usage](#usage)
19
19
  - [Phlex Example](#phlex-example)
20
+ - [Instance Variables](#instance-variables)
21
+ - [Extending initializer logic](#extending-initializer-logic)
20
22
  - [Method Visibility](#method-visibility)
21
23
  - [Development](#development)
22
24
  - [Contributing](#contributing)
@@ -68,6 +70,54 @@ class Components::HelloWorld < Phlex::HTML
68
70
  end
69
71
  ```
70
72
 
73
+ ### Instance Variables
74
+
75
+ If you need more instance variables beside defined props, define them within the class body, not the initializer.
76
+
77
+ ```ruby
78
+ class MyClass
79
+ extend T::Sig
80
+ include SorbetTyped::Props
81
+
82
+ prop :my_prop, Integer
83
+
84
+ @my_var = T.let(nil, T.nilable(String))
85
+
86
+ sig { void }
87
+ def foo
88
+ T.reveal_type(my_prop) # => Integer
89
+ T.reveal_type(@my_var) # => T.nilable(String)
90
+ end
91
+ end
92
+ ```
93
+
94
+ ### Extending initializer logic
95
+
96
+ If you want to implement some logic on instance initialization, implementing a custom `initializer` method would require
97
+ you to write a lot of boilerplate code to redefine the method signature and instance variable initialization normally
98
+ done by `SorbetTyped::Props`.
99
+
100
+ To allow you to nonetheless extend initialization, `SorbetTyped::Props` implements the overridable method
101
+ `post_props_initialize`. It gets called right after prop initialization and has access to all props to do validation or
102
+ whatever you like. Override this method in your own class to implement whatever custom logic you need.
103
+
104
+ ```ruby
105
+ class MyClass
106
+ extend T::Sig
107
+ include SorbetTyped::Props
108
+
109
+ prop :my_prop, Integer
110
+
111
+ sig { override.void }
112
+ def post_props_initialize
113
+ raise 'invalid' if my_prop.negative?
114
+ end
115
+ end
116
+ ```
117
+
118
+ **Note:** you cannot do instance variable initialization here. Define them [within the class body](#instance-variables)
119
+ instead.
120
+
71
121
  ### Method Visibility
72
122
 
73
123
  If you want attributes in your initializer but not be part of your public class interface, you can use ruby's visibility
@@ -5,7 +5,7 @@
5
5
 
6
6
  module SorbetTyped
7
7
  module Props
8
- VERSION = '1.0.4'
8
+ VERSION = '1.1.0'
9
9
  end
10
10
  end
11
11
 
@@ -9,12 +9,28 @@ module SorbetTyped
9
9
  # interface usable. It's just a wrapper around T::Props and
10
10
  # T::Props::Constructor. It's also the ancestor the custom tapioca compiler
11
11
  # looks for when generating initializer type annotation rbis.
12
+ #
13
+ # :reek:ModuleInitialize -- we accept this here. This module defines an
14
+ # initialize method via T::Props::Constructor nonetheless, we only extend it.
15
+ # It shouldn't really be used with other initializers anyway.
12
16
  module Props
17
+ extend T::Sig
13
18
  extend T::Helpers
14
19
 
15
20
  include T::Props
16
21
  include T::Props::Constructor
17
22
 
18
23
  mixes_in_class_methods(T::Props::ClassMethods)
24
+
25
+ sig { params(args: T.anything, kwargs: T.anything).void }
26
+ def initialize(*args, **kwargs)
27
+ super
28
+ post_props_initialize
29
+ end
30
+
31
+ private
32
+
33
+ sig { overridable.void }
34
+ def post_props_initialize; end
19
35
  end
20
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet_typed-props
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Kramer
@@ -18,7 +18,7 @@ dependencies:
18
18
  version: 0.6.0
19
19
  - - "<="
20
20
  - !ruby/object:Gem::Version
21
- version: 0.6.12780
21
+ version: 0.6.12784
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -28,7 +28,7 @@ dependencies:
28
28
  version: 0.6.0
29
29
  - - "<="
30
30
  - !ruby/object:Gem::Version
31
- version: 0.6.12780
31
+ version: 0.6.12784
32
32
  - !ruby/object:Gem::Dependency
33
33
  name: tapioca
34
34
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ metadata:
75
75
  homepage_uri: https://gitlab.com/sorbet_typed/props
76
76
  source_code_uri: https://gitlab.com/sorbet_typed/props
77
77
  rubygems_mfa_required: 'true'
78
+ changelog_uri: https://gitlab.com/sorbet_typed/props/-/blob/main/CHANGELOG.md
78
79
  rdoc_options: []
79
80
  require_paths:
80
81
  - lib