grape_sorbet 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa4f8d64cc6cbf5839f525d1c1e246386510695be350c4bf1ed1298b52b8c9a4
4
- data.tar.gz: baeca4c981155f04394d3dab717a300c923f41aa063516c4eb0430943e0ba756
3
+ metadata.gz: b090755b28d1fff8fb2de659c1196985f0904986ed09395964a636a0d8263645
4
+ data.tar.gz: a379078b3bad1bc4b16b67b5d0a417993b58d1302bf85656c6b1eb5a0d28eacd
5
5
  SHA512:
6
- metadata.gz: 9a7f6cb172c0c73adf41a2992b620f45962459baeeb7f19cc916036776a010018a28a5f0dac752a55a2e1c623ee4e394a6654fd3f2139750e73fdc278a5f8a6d
7
- data.tar.gz: 59580b70030d1d8d013191c55671a82daa854e1a536ecc67acb1a1ee70e1e907086a76b9eddb5022eadb03161c0043c241c7fc5f8a831c4cdf0b1c0f12e09597
6
+ metadata.gz: e9c858df3843df3547fec4b9283a760704746d19d5fa79975dee8ca65204b5b8d3670a905c01ed123180be51eba01ed6fa73309209d58a97deb413a766c65e0e
7
+ data.tar.gz: f0e62315163f3d87326b6f967f7ecfe54c13005361e951549478acf12a313808c0a4424c061384fc2661a9b46f33e2a22a22e47f4d949d238f552611b91cd7f0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.0.6 (2024-06-25)
2
+
3
+ - Add support for `rescue_from`
4
+
5
+ ## 0.0.5 (2024-06-24)
6
+
7
+ - Ignore anonymous helpers
8
+
1
9
  ## 0.0.4 (2024-06-24)
2
10
 
3
11
  - Update `grape.rbi`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape_sorbet (0.0.4)
4
+ grape_sorbet (0.0.6)
5
5
  activesupport
6
6
  grape (~> 2.0)
7
7
  sorbet-runtime (~> 0.5.10741)
data/README.md CHANGED
@@ -10,12 +10,11 @@ grape_sorbet is a gem that provides hand written signatures and a Tapioca DSL co
10
10
 
11
11
  Install the gem and add to the application's Gemfile by executing:
12
12
 
13
- $ bundle add r --github=https://github.com/thatch-health/grape_sorbet
13
+ $ bundle add grape_sorbet
14
14
 
15
15
  If bundler is not being used to manage dependencies, install the gem by executing:
16
16
 
17
- $ gem install specific_install
18
- $ gem specific_install https://github.com/thatch-health/grape_sorbet.git
17
+ $ gem install grape_sorbet
19
18
 
20
19
  After installing the gem, make sure to run `bundle exec tapioca gem grape_sorbet` in your project to import the hand written signatures.
21
20
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module GrapeSorbet
5
- VERSION = "0.0.4"
5
+ VERSION = "0.0.6"
6
6
  end
@@ -67,8 +67,10 @@ module Tapioca
67
67
  sig { override.void }
68
68
  def decorate
69
69
  create_classes_and_includes
70
- create_routing_methods
70
+
71
71
  create_callbacks_methods
72
+ create_request_response_methods
73
+ create_routing_methods
72
74
  end
73
75
 
74
76
  class << self
@@ -108,6 +110,14 @@ module Tapioca
108
110
  )
109
111
  end
110
112
 
113
+ sig { returns(RBI::Scope) }
114
+ def request_response_methods_module
115
+ @request_response_methods_module ||= T.let(
116
+ api.create_module(RequestResponseMethodsModuleName),
117
+ T.nilable(RBI::Scope),
118
+ )
119
+ end
120
+
111
121
  sig { returns(RBI::Scope) }
112
122
  def routing_methods_module
113
123
  @routing_methods_module ||= T.let(
@@ -119,6 +129,7 @@ module Tapioca
119
129
  sig { void }
120
130
  def create_classes_and_includes
121
131
  api.create_extend(CallbacksMethodsModuleName)
132
+ api.create_extend(RequestResponseMethodsModuleName)
122
133
  api.create_extend(RoutingMethodsModuleName)
123
134
  create_api_class
124
135
  create_endpoint_class
@@ -137,14 +148,10 @@ module Tapioca
137
148
  def create_endpoint_class
138
149
  superclass = "::Grape::Endpoint"
139
150
 
140
- helper_mods = constant.namespace_stackable(:helpers)
141
-
142
- if helper_mods.any? { |mod| mod.name.nil? }
143
- raise "Cannot compile Grape API with anonymous helpers"
144
- end
151
+ named_helper_mods = constant.namespace_stackable(:helpers).reject { |mod| mod.name.nil? }
145
152
 
146
153
  api.create_class(EndpointClassName, superclass_name: superclass) do |klass|
147
- helper_mods.each do |mod|
154
+ named_helper_mods.each do |mod|
148
155
  klass.create_include(mod.name)
149
156
  end
150
157
  end
@@ -163,6 +170,21 @@ module Tapioca
163
170
  end
164
171
  end
165
172
 
173
+ sig { void }
174
+ def create_request_response_methods
175
+ request_response_methods_module.create_method(
176
+ "rescue_from",
177
+ parameters: [
178
+ create_rest_param("args", type: "T.untyped"),
179
+ create_block_param(
180
+ "block",
181
+ type: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: Exception).void)",
182
+ ),
183
+ ],
184
+ return_type: "void",
185
+ )
186
+ end
187
+
166
188
  sig { void }
167
189
  def create_routing_methods
168
190
  HTTP_VERB_METHODS.each do |verb|
@@ -8,6 +8,7 @@ module Tapioca
8
8
  extend T::Sig
9
9
 
10
10
  CallbacksMethodsModuleName = "GeneratedCallbacksMethods"
11
+ RequestResponseMethodsModuleName = "GeneratedRequestResponseMethods"
11
12
  RoutingMethodsModuleName = "GeneratedRoutingMethods"
12
13
 
13
14
  APIInstanceClassName = "PrivateAPIInstance"
data/rbi/grape.rbi CHANGED
@@ -22,11 +22,16 @@ module Grape
22
22
  sig { params(name: Symbol, block: T.proc.bind(Grape::Validations::ParamsScope).void).void }
23
23
  def params(name, &block); end
24
24
  end
25
+
26
+ module ClassMethods
27
+ sig { params(new_modules: T.untyped, block: T.nilable(T.proc.bind(Grape::DSL::Helpers::BaseHelper).void)).void }
28
+ def helpers(*new_modules, &block); end
29
+ end
25
30
  end
26
31
 
27
32
  module RequestResponse
28
33
  module ClassMethods
29
- sig { params(args: T.untyped, block: T.proc.bind(Grape::Endpoint).void).void }
34
+ sig { params(args: T.untyped, block: T.proc.bind(Grape::Endpoint).params(e: Exception).void).void }
30
35
  def rescue_from(*args, &block); end
31
36
  end
32
37
  end
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
4
+ version: 0.0.6
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-24 00:00:00.000000000 Z
11
+ date: 2024-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport