grape_sorbet 0.0.1 → 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 +11 -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 +31 -3
- data/lib/tapioca/dsl/helpers/grape_constants_helper.rb +1 -0
- data/rbi/grape.rbi +0 -5
- metadata +3 -2
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
ADDED
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
@@ -68,6 +68,7 @@ module Tapioca
|
|
68
68
|
def decorate
|
69
69
|
create_classes_and_includes
|
70
70
|
create_routing_methods
|
71
|
+
create_callbacks_methods
|
71
72
|
end
|
72
73
|
|
73
74
|
class << self
|
@@ -79,6 +80,11 @@ module Tapioca
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
83
|
+
CALLBACKS_METHODS = T.let(
|
84
|
+
[:before, :before_validation, :after_validation, :after, :finally].freeze,
|
85
|
+
T::Array[Symbol],
|
86
|
+
)
|
87
|
+
|
82
88
|
HTTP_VERB_METHODS = T.let(
|
83
89
|
[:get, :post, :put, :patch, :delete, :head, :options].freeze,
|
84
90
|
T::Array[Symbol],
|
@@ -94,6 +100,14 @@ module Tapioca
|
|
94
100
|
)
|
95
101
|
end
|
96
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
|
+
|
97
111
|
sig { returns(RBI::Scope) }
|
98
112
|
def routing_methods_module
|
99
113
|
@routing_methods_module ||= T.let(
|
@@ -104,6 +118,7 @@ module Tapioca
|
|
104
118
|
|
105
119
|
sig { void }
|
106
120
|
def create_classes_and_includes
|
121
|
+
api.create_extend(CallbacksMethodsModuleName)
|
107
122
|
api.create_extend(RoutingMethodsModuleName)
|
108
123
|
create_api_class
|
109
124
|
create_endpoint_class
|
@@ -135,6 +150,19 @@ module Tapioca
|
|
135
150
|
end
|
136
151
|
end
|
137
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
|
+
|
138
166
|
sig { void }
|
139
167
|
def create_routing_methods
|
140
168
|
HTTP_VERB_METHODS.each do |verb|
|
@@ -142,7 +170,7 @@ module Tapioca
|
|
142
170
|
verb.to_s,
|
143
171
|
parameters: [
|
144
172
|
create_rest_param("args", type: "T.untyped"),
|
145
|
-
create_block_param("
|
173
|
+
create_block_param("block", type: "T.nilable(T.proc.bind(#{EndpointClassName}).void)"),
|
146
174
|
],
|
147
175
|
return_type: "void",
|
148
176
|
)
|
@@ -152,8 +180,8 @@ module Tapioca
|
|
152
180
|
"route_param",
|
153
181
|
parameters: [
|
154
182
|
create_param("param", type: "Symbol"),
|
155
|
-
create_opt_param("options", type: "T
|
156
|
-
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)"),
|
157
185
|
],
|
158
186
|
return_type: "void",
|
159
187
|
)
|
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
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape_sorbet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thatch Health, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".editorconfig"
|
64
64
|
- ".rubocop.yml"
|
65
65
|
- ".ruby-version"
|
66
|
+
- CHANGELOG.md
|
66
67
|
- CODE_OF_CONDUCT.md
|
67
68
|
- Gemfile
|
68
69
|
- Gemfile.lock
|