grape_sorbet 0.0.2 → 0.0.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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +23 -1
- data/lib/grape_sorbet/version.rb +1 -1
- data/lib/tapioca/dsl/compilers/grape_endpoints.rb +29 -21
- data/lib/tapioca/dsl/helpers/grape_constants_helper.rb +1 -0
- data/rbi/grape.rbi +0 -5
- 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: afca4010268efe01d37b64b7cfd4bbd7f6266779a3a135ab04fe14869ab71daf
|
4
|
+
data.tar.gz: ee494b0147c0b9d32ae90a5a1fba81218687b26396131a56ff9a1bb16306d693
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 122aa7dab2572d6df1cfc79a3ec7a80b652f5ad7d5d51d87b0e9077385e3fb8041fd75b190f76ce4c58b4f1aea575dd1194d505b21c5d9ff32d80b9fca1aa33a
|
7
|
+
data.tar.gz: 4eb298722d0e14cb745a20917899825463fd50d6b87b0e1d9541566c9bc5961effec782c7ec767cacc9bcf37536596e0f885c3ae9eb5bdf60717f32d1833c341
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -90,7 +90,29 @@ module Twitter
|
|
90
90
|
end
|
91
91
|
```
|
92
92
|
|
93
|
-
At this point Sorbet is still reporting errors in the `get :home_timeline` block, because it doesn't know that these blocks are executed in a context where the `Helpers` module methods will be available. The Tapioca compiler provided by this gem will fix that. Run `bundle exec tapioca dsl`. This should generate a `sorbet/rbi/dsl/twitter/api.rbi` file (assuming the source file is in `lib/twitter/api.rb`).
|
93
|
+
At this point Sorbet is still reporting errors in the `get :home_timeline` block, because it doesn't know that these blocks are executed in a context where the `Helpers` module methods will be available. The Tapioca compiler provided by this gem will fix that. Run `bundle exec tapioca dsl`. This should generate a `sorbet/rbi/dsl/twitter/api.rbi` file (assuming the source file is in `lib/twitter/api.rb`).
|
94
|
+
|
95
|
+
After this, Sorbet should no longer report any errors.
|
96
|
+
|
97
|
+
## Limitations and known issues
|
98
|
+
|
99
|
+
### Subclassing from `Grape::API::Instance` instead of `Grape::API`
|
100
|
+
|
101
|
+
Grape overrides `Grape::API.new` and uses the `inherited` hook so that subclasses of `Grape::API` are really subclasses of `Grape::API::Instance`.
|
102
|
+
|
103
|
+
This might be fixable in a future update of grape_sorbet, but is very low priority.
|
104
|
+
|
105
|
+
### Not being able to call `helpers` with block arguments
|
106
|
+
|
107
|
+
Possibly fixable in a future update.
|
108
|
+
|
109
|
+
### Having to use `T.bind(self, T.any(Grape::Endpoint, <HelpersModuleName>))` in helper methods
|
110
|
+
|
111
|
+
Possibly fixable in a future update.
|
112
|
+
|
113
|
+
### Having to use `T.bind(self, T.any(Grape::Endpoint, <HelpersModuleName>))` in `before` and `after` callback blocks
|
114
|
+
|
115
|
+
The compiler already generates proper signatures for callback methods so `T.bind` should not be needed (and is in fact unneeded for the other callback methods, `before_validation`, `after_validation` and `finally`). The reason it doesn't work for `before` and `after` is because of a [bug](https://github.com/sorbet/sorbet/issues/7950) in Sorbet itself.
|
94
116
|
|
95
117
|
## Development
|
96
118
|
|
data/lib/grape_sorbet/version.rb
CHANGED
@@ -80,13 +80,13 @@ module Tapioca
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
|
-
[:
|
83
|
+
CALLBACKS_METHODS = T.let(
|
84
|
+
[:before, :before_validation, :after_validation, :after, :finally].freeze,
|
85
85
|
T::Array[Symbol],
|
86
86
|
)
|
87
87
|
|
88
|
-
|
89
|
-
[:
|
88
|
+
HTTP_VERB_METHODS = T.let(
|
89
|
+
[:get, :post, :put, :patch, :delete, :head, :options].freeze,
|
90
90
|
T::Array[Symbol],
|
91
91
|
)
|
92
92
|
|
@@ -100,6 +100,14 @@ module Tapioca
|
|
100
100
|
)
|
101
101
|
end
|
102
102
|
|
103
|
+
sig { returns(RBI::Scope) }
|
104
|
+
def callbacks_methods_module
|
105
|
+
@callbacks_methods_module ||= T.let(
|
106
|
+
api.create_module(CallbacksMethodsModuleName),
|
107
|
+
T.nilable(RBI::Scope),
|
108
|
+
)
|
109
|
+
end
|
110
|
+
|
103
111
|
sig { returns(RBI::Scope) }
|
104
112
|
def routing_methods_module
|
105
113
|
@routing_methods_module ||= T.let(
|
@@ -110,6 +118,7 @@ module Tapioca
|
|
110
118
|
|
111
119
|
sig { void }
|
112
120
|
def create_classes_and_includes
|
121
|
+
api.create_extend(CallbacksMethodsModuleName)
|
113
122
|
api.create_extend(RoutingMethodsModuleName)
|
114
123
|
create_api_class
|
115
124
|
create_endpoint_class
|
@@ -141,6 +150,19 @@ module Tapioca
|
|
141
150
|
end
|
142
151
|
end
|
143
152
|
|
153
|
+
sig { void }
|
154
|
+
def create_callbacks_methods
|
155
|
+
CALLBACKS_METHODS.each do |callback|
|
156
|
+
callbacks_methods_module.create_method(
|
157
|
+
callback.to_s,
|
158
|
+
parameters: [
|
159
|
+
create_block_param("block", type: "T.proc.bind(#{EndpointClassName}).void"),
|
160
|
+
],
|
161
|
+
return_type: "void",
|
162
|
+
)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
144
166
|
sig { void }
|
145
167
|
def create_routing_methods
|
146
168
|
HTTP_VERB_METHODS.each do |verb|
|
@@ -148,7 +170,7 @@ module Tapioca
|
|
148
170
|
verb.to_s,
|
149
171
|
parameters: [
|
150
172
|
create_rest_param("args", type: "T.untyped"),
|
151
|
-
create_block_param("
|
173
|
+
create_block_param("block", type: "T.nilable(T.proc.bind(#{EndpointClassName}).void)"),
|
152
174
|
],
|
153
175
|
return_type: "void",
|
154
176
|
)
|
@@ -158,26 +180,12 @@ module Tapioca
|
|
158
180
|
"route_param",
|
159
181
|
parameters: [
|
160
182
|
create_param("param", type: "Symbol"),
|
161
|
-
create_opt_param("options", type: "T
|
162
|
-
create_block_param("
|
183
|
+
create_opt_param("options", type: "T::Hash[Symbol, T.untyped]", default: "{}"),
|
184
|
+
create_block_param("block", type: "T.nilable(T.proc.bind(T.class_of(#{APIInstanceClassName})).void)"),
|
163
185
|
],
|
164
186
|
return_type: "void",
|
165
187
|
)
|
166
188
|
end
|
167
|
-
|
168
|
-
sig { void }
|
169
|
-
def create_callbacks_methods
|
170
|
-
CALLBACKS_METHODS.each do |callback|
|
171
|
-
routing_methods_module.create_method(
|
172
|
-
callback.to_s,
|
173
|
-
parameters: [
|
174
|
-
create_rest_param("args", type: "T.untyped"),
|
175
|
-
create_block_param("blk", type: "T.nilable(T.proc.bind(#{EndpointClassName}).void)"),
|
176
|
-
],
|
177
|
-
return_type: "void",
|
178
|
-
)
|
179
|
-
end
|
180
|
-
end
|
181
189
|
end
|
182
190
|
end
|
183
191
|
end
|
data/rbi/grape.rbi
CHANGED
@@ -2,11 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module Grape
|
5
|
-
module DSL::Callbacks::ClassMethods
|
6
|
-
sig { params(block: T.proc.bind(Grape::Endpoint).void).void }
|
7
|
-
def before(&block); end
|
8
|
-
end
|
9
|
-
|
10
5
|
module DSL::Desc
|
11
6
|
# grape evaluates config_block in the context of a dynamically created module that implements the DSL it exposes
|
12
7
|
# at runtime. There's no good way to represent this statically, so block is just typed as T.untyped to prevent
|