grape_sorbet 0.0.7 → 0.0.9

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: 3f1483462bce00425216e9bd1be3137206600302347695f41aed3b8dcc1b19a7
4
- data.tar.gz: e1f75b93fac21bf377184bcdc9224acc28da3dd8e885498fcc8359b22f0dbca7
3
+ metadata.gz: d4014b15113664de2c3ef60d30403fbe67f7d348d1f6c80fe7ac38d12b071646
4
+ data.tar.gz: 58c89b271a8ddec8a5d97a28044f8f46ad9259d2749371a96ca4c2a3362b235e
5
5
  SHA512:
6
- metadata.gz: b42428f7c407aa7651a7db09e37e7c85219f3998ca0d53335d4751d8b42a13e736f5c3df681f808f01830d02f34c94574dd9ab6607613f2bbbac775dd61508bf
7
- data.tar.gz: 59ae1b6e5bd26bd0fe5add3810b789df8f2b714484d1795d32f18b4484f6b33972cb2d2c1b180bfa6e3b7df6d5bbfd6c0571c575172502424199e22b338598ab
6
+ metadata.gz: f306c2fd09fe53fe081259dfb9df0cbd47d0923040d8593f6ea15a5bf4fbb6d837b0ec46a08188a673b1b1b03fead58dbab121f565659f1f6a8336f252ae6a79
7
+ data.tar.gz: 6f57c28ba24c5d771d38203a29e856cb7e54726685ff3a027cc7da42450a210019f85596eceaa1e5d62a9bc7bd7a328d11076c45ecfeb8119db70be068265a9d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.0.9 (2024-07-15)
2
+
3
+ - Entity name setter method
4
+
5
+ ## 0.0.8 (2024-07-12)
6
+
7
+ - Improve types for `rescue_from`
8
+
1
9
  ## 0.0.7 (2024-07-03)
2
10
 
3
11
  - Add signatures for `error!` and a few other methods
data/Gemfile CHANGED
@@ -32,4 +32,6 @@ group :test do
32
32
  gem "minitest-reporters", "~> 1.4"
33
33
 
34
34
  gem "simplecov", require: false
35
+
36
+ gem "grape-entity", require: false
35
37
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape_sorbet (0.0.7)
4
+ grape_sorbet (0.0.9)
5
5
  activesupport
6
6
  grape (~> 2.0)
7
7
  sorbet-runtime (~> 0.5.10741)
@@ -53,10 +53,13 @@ GEM
53
53
  mustermann-grape (~> 1.1.0)
54
54
  rack (>= 2)
55
55
  zeitwerk
56
+ grape-entity (1.0.1)
57
+ activesupport (>= 3.0.0)
58
+ multi_json (>= 1.3.2)
56
59
  i18n (1.14.5)
57
60
  concurrent-ruby (~> 1.0)
58
61
  io-console (0.7.2)
59
- irb (1.13.2)
62
+ irb (1.14.0)
60
63
  rdoc (>= 4.0.0)
61
64
  reline (>= 0.4.2)
62
65
  json (2.7.2)
@@ -67,6 +70,7 @@ GEM
67
70
  builder
68
71
  minitest (>= 5.0)
69
72
  ruby-progressbar
73
+ multi_json (1.15.0)
70
74
  mustermann (3.0.0)
71
75
  ruby2_keywords (~> 0.0.1)
72
76
  mustermann-grape (1.1.0)
@@ -74,14 +78,14 @@ GEM
74
78
  mutex_m (0.2.0)
75
79
  netrc (0.11.0)
76
80
  parallel (1.25.1)
77
- parser (3.3.3.0)
81
+ parser (3.3.4.0)
78
82
  ast (~> 2.4.1)
79
83
  racc
80
84
  prism (0.30.0)
81
85
  psych (5.1.2)
82
86
  stringio
83
87
  racc (1.8.0)
84
- rack (3.1.6)
88
+ rack (3.1.7)
85
89
  rainbow (3.1.1)
86
90
  rake (13.2.1)
87
91
  rbi (0.1.13)
@@ -94,20 +98,20 @@ GEM
94
98
  io-console (~> 0.5)
95
99
  rexml (3.3.1)
96
100
  strscan
97
- rubocop (1.64.1)
101
+ rubocop (1.65.0)
98
102
  json (~> 2.3)
99
103
  language_server-protocol (>= 3.17.0)
100
104
  parallel (~> 1.10)
101
105
  parser (>= 3.3.0.2)
102
106
  rainbow (>= 2.2.2, < 4.0)
103
- regexp_parser (>= 1.8, < 3.0)
107
+ regexp_parser (>= 2.4, < 3.0)
104
108
  rexml (>= 3.2.5, < 4.0)
105
109
  rubocop-ast (>= 1.31.1, < 2.0)
106
110
  ruby-progressbar (~> 1.7)
107
111
  unicode-display_width (>= 2.4.0, < 3.0)
108
112
  rubocop-ast (1.31.3)
109
113
  parser (>= 3.3.1.0)
110
- rubocop-minitest (0.35.0)
114
+ rubocop-minitest (0.35.1)
111
115
  rubocop (>= 1.61, < 2.0)
112
116
  rubocop-ast (>= 1.31.1, < 2.0)
113
117
  rubocop-performance (1.21.1)
@@ -127,23 +131,23 @@ GEM
127
131
  simplecov_json_formatter (~> 0.1)
128
132
  simplecov-html (0.12.3)
129
133
  simplecov_json_formatter (0.1.4)
130
- sorbet (0.5.11466)
131
- sorbet-static (= 0.5.11466)
132
- sorbet-runtime (0.5.11466)
133
- sorbet-static (0.5.11466-aarch64-linux)
134
- sorbet-static (0.5.11466-universal-darwin)
135
- sorbet-static (0.5.11466-x86_64-linux)
136
- sorbet-static-and-runtime (0.5.11466)
137
- sorbet (= 0.5.11466)
138
- sorbet-runtime (= 0.5.11466)
139
- spoom (1.3.2)
134
+ sorbet (0.5.11481)
135
+ sorbet-static (= 0.5.11481)
136
+ sorbet-runtime (0.5.11481)
137
+ sorbet-static (0.5.11481-aarch64-linux)
138
+ sorbet-static (0.5.11481-universal-darwin)
139
+ sorbet-static (0.5.11481-x86_64-linux)
140
+ sorbet-static-and-runtime (0.5.11481)
141
+ sorbet (= 0.5.11481)
142
+ sorbet-runtime (= 0.5.11481)
143
+ spoom (1.3.3)
140
144
  erubi (>= 1.10.0)
141
- prism (>= 0.19.0)
145
+ prism (>= 0.28.0)
142
146
  sorbet-static-and-runtime (>= 0.5.10187)
143
147
  thor (>= 0.19.2)
144
148
  stringio (3.1.1)
145
149
  strscan (3.1.0)
146
- tapioca (0.15.0)
150
+ tapioca (0.15.1)
147
151
  bundler (>= 2.2.25)
148
152
  netrc (>= 0.11.0)
149
153
  parallel (>= 1.21.0)
@@ -169,6 +173,7 @@ PLATFORMS
169
173
 
170
174
  DEPENDENCIES
171
175
  bundler-audit
176
+ grape-entity
172
177
  grape_sorbet!
173
178
  irb
174
179
  minitest (~> 5.0)
@@ -185,4 +190,4 @@ DEPENDENCIES
185
190
  tapioca
186
191
 
187
192
  BUNDLED WITH
188
- 2.5.9
193
+ 2.5.15
data/grape_sorbet.gemspec CHANGED
@@ -31,9 +31,9 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
- spec.add_runtime_dependency("activesupport")
35
- spec.add_runtime_dependency("grape", "~> 2.0")
36
- spec.add_runtime_dependency("sorbet-runtime", "~> 0.5.10741")
34
+ spec.add_dependency("activesupport")
35
+ spec.add_dependency("grape", "~> 2.0")
36
+ spec.add_dependency("sorbet-runtime", "~> 0.5.10741")
37
37
 
38
38
  # For more information and examples about making a new gem, check out our
39
39
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -0,0 +1,89 @@
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ require "sorbet-runtime"
5
+
6
+ module GrapeSorbet
7
+ # This is a patch for Grape::Entity to make it easier to define custom entity names when using Sorbet.
8
+ #
9
+ # This patch defines a class setter `entity_name=` that can be used to define a custom entity name in a single line,
10
+ # while still working as expected with grape-swagger:
11
+ # ```
12
+ # class Link < Grape::Entity
13
+ # self.entity_name = "LinkedStatus"
14
+ # end
15
+ # ```
16
+ #
17
+ # Without this patch, you would have to define a custom entity name like this:
18
+ # ```
19
+ # class Link < Grape::Entity
20
+ # extend T::Sig
21
+ #
22
+ # sig { returns(String) }
23
+ # def self.entity_name
24
+ # "LinkedStatus"
25
+ # end
26
+ # end
27
+ # ```
28
+ #
29
+ # or even more verbose, if you're using the `Style/ClassMethodsDefinitions` Rubocop rule with
30
+ # `EnforcedStyle: self_class`:
31
+ # ```
32
+ # class Link < Grape::Entity
33
+ # class << self
34
+ # extend T::Sig
35
+ #
36
+ # sig { returns(String) }
37
+ # def entity_name
38
+ # "LinkedStatus"
39
+ # end
40
+ # end
41
+ # end
42
+ # ```
43
+ module GrapeEntityName
44
+ extend T::Sig
45
+
46
+ include Kernel
47
+
48
+ # Sets the entity name.
49
+ #
50
+ # Used by grape-swagger to define a custom name to use in the OpenAPI schema instead of generating it from the
51
+ # fully qualified class name.
52
+ #
53
+ # @param entity_name [String] The custom entity name.
54
+ sig { params(entity_name: String).returns(String) }
55
+ attr_writer :entity_name
56
+
57
+ # Returns the custom entity name if one has been set (using `entity_name=`), otherwise raises an error.
58
+ #
59
+ # @return [String] The custom entity name.
60
+ # @raise [StandardError] If no custom entity name has been set.
61
+ sig { returns(String) }
62
+ def entity_name
63
+ @entity_name = T.let(@entity_name, T.nilable(String))
64
+
65
+ return @entity_name unless @entity_name.nil?
66
+
67
+ raise "entity_name has not been set for #{self}, call `#{self}.entity_name = \"...\"` to set it"
68
+ end
69
+
70
+ sig { params(method_name: T.any(String, Symbol), include_all: T.untyped).returns(T::Boolean) }
71
+ def respond_to?(method_name, include_all = false)
72
+ # grape-swagger checks if the model class responds to `:entity_name`, so we need to return false if
73
+ # `@entity_name` is nil (meaning `entity_name=` was never called).
74
+ if method_name.to_sym == :entity_name
75
+ return !!(defined?(@entity_name) && !@entity_name.nil?)
76
+ end
77
+
78
+ super
79
+ end
80
+ end
81
+ end
82
+
83
+ begin
84
+ require "grape-entity"
85
+ rescue LoadError
86
+ return
87
+ else
88
+ Grape::Entity.extend(GrapeSorbet::GrapeEntityName)
89
+ end
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module GrapeSorbet
5
- VERSION = "0.0.7"
5
+ VERSION = "0.0.9"
6
6
  end
data/lib/grape_sorbet.rb CHANGED
@@ -5,3 +5,4 @@ module GrapeSorbet
5
5
  end
6
6
 
7
7
  require_relative "grape_sorbet/version"
8
+ require_relative "grape_sorbet/grape_entity_name"
@@ -172,16 +172,30 @@ module Tapioca
172
172
 
173
173
  sig { void }
174
174
  def create_request_response_methods
175
- request_response_methods_module.create_method(
175
+ sigs = [
176
+ request_response_methods_module.create_sig(
177
+ parameters: {
178
+ args: "Symbol",
179
+ block: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: Exception).void)",
180
+ },
181
+ return_type: "void",
182
+ ),
183
+ request_response_methods_module.create_sig(
184
+ type_parameters: ["E"],
185
+ parameters: {
186
+ args: "T::Class[T.all(::Exception, T.type_parameter(:E))]",
187
+ block: "T.nilable(T.proc.bind(#{EndpointClassName}).params(e: T.type_parameter(:E)).void)",
188
+ },
189
+ return_type: "void",
190
+ ),
191
+ ]
192
+ request_response_methods_module.create_method_with_sigs(
176
193
  "rescue_from",
194
+ sigs: sigs,
177
195
  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
- ),
196
+ RBI::RestParam.new("args"),
197
+ RBI::BlockParam.new("block"),
183
198
  ],
184
- return_type: "void",
185
199
  )
186
200
  end
187
201
 
data/rbi/grape.rbi CHANGED
@@ -51,7 +51,15 @@ module Grape
51
51
 
52
52
  module RequestResponse
53
53
  module ClassMethods
54
- sig { params(args: T.untyped, block: T.proc.bind(Grape::Endpoint).params(e: Exception).void).void }
54
+ sig { params(args: Symbol, block: T.nilable(T.proc.bind(Grape::Endpoint).params(e: Exception).void)).void }
55
+ sig do
56
+ type_parameters(:E)
57
+ .params(
58
+ args: T::Class[T.all(Exception, T.type_parameter(:E))],
59
+ block: T.proc.bind(Grape::Endpoint).params(e: T.type_parameter(:E)).void,
60
+ )
61
+ .void
62
+ end
55
63
  def rescue_from(*args, &block); end
56
64
  end
57
65
  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.7
4
+ version: 0.0.9
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-07-03 00:00:00.000000000 Z
11
+ date: 2024-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -72,6 +72,7 @@ files:
72
72
  - Rakefile
73
73
  - grape_sorbet.gemspec
74
74
  - lib/grape_sorbet.rb
75
+ - lib/grape_sorbet/grape_entity_name.rb
75
76
  - lib/grape_sorbet/version.rb
76
77
  - lib/tapioca/dsl/compilers/grape_endpoints.rb
77
78
  - lib/tapioca/dsl/helpers/grape_constants_helper.rb