tapioca_dsl_compiler_store_model 0.1.1 → 0.1.3
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 +4 -4
- data/README.md +3 -13
- data/lib/tapioca/dsl/compilers/store_model.rb +9 -7
- data/lib/tapioca_dsl_compiler_store_model/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cd663ae85d93ae01a2e4b42daa3870976b10de692ed58bed169016b051a2e42
|
4
|
+
data.tar.gz: 6d39aa14b9f2510eea4bbd67d8c0fd66eb9cc27818c02cdc14443187ad25e1e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d945c99a1571c75eda1f7f1f6d01a8c82ebcda9a4c8dc3cdf677cff9daebed3d2725bacee5dc25e71f8cf85d7c2b7917a0ae124fa6191372c5ccea7484233c4
|
7
|
+
data.tar.gz: 2f433c5753cd670ed30c51f49c99af4926411015167679bb0d7644f646fe3de0b0e069f3d60fd8009e6fa2a94f9c9d289010d915410051856832eae967c473a6
|
data/README.md
CHANGED
@@ -2,15 +2,6 @@
|
|
2
2
|
|
3
3
|
A [Tapioca](https://github.com/Shopify/tapioca) DSL compiler that generates RBI files for [StoreModel](https://github.com/DmitryTsepelev/store_model) attributes in ActiveRecord models.
|
4
4
|
|
5
|
-
StoreModel adds JSON-backed attributes to ActiveRecord models, and this gem provides Sorbet type signatures for the methods that StoreModel dynamically generates.
|
6
|
-
|
7
|
-
## Features
|
8
|
-
|
9
|
-
- **Automatic RBI Generation**: Generates Sorbet RBI files for StoreModel attributes
|
10
|
-
- **Comprehensive Type Coverage**: Supports both single and array StoreModel types
|
11
|
-
- **Build Methods**: Generates signatures for `build_*` methods created by StoreModel
|
12
|
-
- **Tapioca Integration**: Follows Tapioca's standard compiler patterns and is automatically discovered
|
13
|
-
|
14
5
|
## Installation
|
15
6
|
|
16
7
|
Add this line to your application's Gemfile:
|
@@ -33,7 +24,7 @@ $ gem install tapioca_dsl_compiler_store_model
|
|
33
24
|
|
34
25
|
## Usage
|
35
26
|
|
36
|
-
Once installed, Tapioca will automatically discover and use
|
27
|
+
Once installed, Tapioca will automatically discover and use this compiler when generating RBI files with `bundle exec tapioca dsl`.
|
37
28
|
|
38
29
|
### Example
|
39
30
|
|
@@ -117,10 +108,9 @@ These features may be added in future versions.
|
|
117
108
|
|
118
109
|
## Requirements
|
119
110
|
|
120
|
-
- Ruby 2
|
121
|
-
- [Tapioca](https://github.com/Shopify/tapioca) 0.
|
111
|
+
- Ruby 3.2+
|
112
|
+
- [Tapioca](https://github.com/Shopify/tapioca) 0.11+
|
122
113
|
- [StoreModel](https://github.com/DmitryTsepelev/store_model) 1.0+
|
123
|
-
- ActiveRecord 6.0+
|
124
114
|
|
125
115
|
## Development
|
126
116
|
|
@@ -5,8 +5,6 @@ module Tapioca
|
|
5
5
|
module Dsl
|
6
6
|
module Compilers
|
7
7
|
class StoreModel < Tapioca::Dsl::Compiler
|
8
|
-
ConstantType = type_member { { fixed: T.class_of(ActiveRecord::Base) } }
|
9
|
-
|
10
8
|
sig { override.returns(T::Enumerable[Module]) }
|
11
9
|
def self.gather_constants
|
12
10
|
return [] unless defined?(::StoreModel)
|
@@ -142,17 +140,20 @@ module Tapioca
|
|
142
140
|
sig { params(mod: T.untyped, attribute_name: String).void }
|
143
141
|
def create_one_of_array_methods(mod, attribute_name)
|
144
142
|
# OneOf array types are dynamically resolved
|
143
|
+
array_type = "T::Array[StoreModel::Model]"
|
144
|
+
nilable_array_type = "T.nilable(#{array_type})"
|
145
|
+
|
145
146
|
mod.create_method(
|
146
147
|
attribute_name,
|
147
|
-
return_type:
|
148
|
+
return_type: nilable_array_type
|
148
149
|
)
|
149
150
|
|
150
151
|
mod.create_method(
|
151
152
|
"#{attribute_name}=",
|
152
153
|
parameters: [create_param("value",
|
153
|
-
type: "T.nilable(T.any(
|
154
|
+
type: "T.nilable(T.any(#{array_type}, " \
|
154
155
|
"T::Array[T::Hash[T.untyped, T.untyped]]))")],
|
155
|
-
return_type:
|
156
|
+
return_type: nilable_array_type
|
156
157
|
)
|
157
158
|
end
|
158
159
|
|
@@ -183,10 +184,11 @@ module Tapioca
|
|
183
184
|
def create_many_store_model_methods(mod, attribute_name, model_klass)
|
184
185
|
return_type = model_klass.name
|
185
186
|
array_type = "T::Array[#{return_type}]"
|
187
|
+
nilable_array_type = "T.nilable(#{array_type})"
|
186
188
|
|
187
189
|
mod.create_method(
|
188
190
|
attribute_name,
|
189
|
-
return_type:
|
191
|
+
return_type: nilable_array_type
|
190
192
|
)
|
191
193
|
|
192
194
|
mod.create_method(
|
@@ -194,7 +196,7 @@ module Tapioca
|
|
194
196
|
parameters: [create_param("value",
|
195
197
|
type: "T.nilable(T.any(#{array_type}, " \
|
196
198
|
"T::Array[T::Hash[T.untyped, T.untyped]]))")],
|
197
|
-
return_type:
|
199
|
+
return_type: nilable_array_type
|
198
200
|
)
|
199
201
|
end
|
200
202
|
end
|