servus 0.2.1 → 0.4.0

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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/servus/event_handler/event_handler_generator.rb +1 -1
  3. data/lib/generators/servus/guard/guard_generator.rb +1 -1
  4. data/lib/generators/servus/guard/templates/guard.rb.erb +5 -3
  5. data/lib/generators/servus/service/service_generator.rb +1 -1
  6. data/lib/servus/base.rb +67 -9
  7. data/lib/servus/config.rb +71 -3
  8. data/lib/servus/events/bus.rb +29 -0
  9. data/lib/servus/events/emitter.rb +15 -0
  10. data/lib/servus/extensions/lazily/call.rb +82 -0
  11. data/lib/servus/extensions/lazily/errors.rb +37 -0
  12. data/lib/servus/extensions/lazily/ext.rb +23 -0
  13. data/lib/servus/extensions/lazily/resolver.rb +32 -0
  14. data/lib/servus/guard.rb +7 -6
  15. data/lib/servus/guards/falsey_guard.rb +3 -3
  16. data/lib/servus/guards/presence_guard.rb +4 -4
  17. data/lib/servus/guards/state_guard.rb +4 -5
  18. data/lib/servus/guards/truthy_guard.rb +3 -3
  19. data/lib/servus/helpers/controller_helpers.rb +40 -0
  20. data/lib/servus/railtie.rb +7 -1
  21. data/lib/servus/support/data_object.rb +80 -0
  22. data/lib/servus/support/errors.rb +16 -0
  23. data/lib/servus/support/lockdown.rb +94 -0
  24. data/lib/servus/support/logger.rb +16 -0
  25. data/lib/servus/support/response.rb +12 -1
  26. data/lib/servus/support/validator.rb +79 -34
  27. data/lib/servus/testing/example_builders.rb +74 -0
  28. data/lib/servus/testing/matchers.rb +99 -0
  29. data/lib/servus/version.rb +1 -1
  30. data/lib/servus.rb +2 -0
  31. metadata +16 -114
  32. data/.claude/commands/check-docs.md +0 -1
  33. data/.claude/commands/consistency-check.md +0 -1
  34. data/.claude/commands/fine-tooth-comb.md +0 -1
  35. data/.claude/commands/red-green-refactor.md +0 -5
  36. data/.claude/settings.json +0 -24
  37. data/.rspec +0 -3
  38. data/.rubocop.yml +0 -27
  39. data/.yardopts +0 -6
  40. data/CHANGELOG.md +0 -122
  41. data/CLAUDE.md +0 -10
  42. data/IDEAS.md +0 -5
  43. data/LICENSE.txt +0 -21
  44. data/READme.md +0 -856
  45. data/Rakefile +0 -45
  46. data/docs/core/1_overview.md +0 -77
  47. data/docs/core/2_architecture.md +0 -120
  48. data/docs/core/3_service_objects.md +0 -121
  49. data/docs/features/1_schema_validation.md +0 -119
  50. data/docs/features/2_error_handling.md +0 -121
  51. data/docs/features/3_async_execution.md +0 -81
  52. data/docs/features/4_logging.md +0 -64
  53. data/docs/features/5_event_bus.md +0 -244
  54. data/docs/features/6_guards.md +0 -356
  55. data/docs/features/guards_naming_convention.md +0 -540
  56. data/docs/guides/1_common_patterns.md +0 -90
  57. data/docs/guides/2_migration_guide.md +0 -175
  58. data/docs/integration/1_configuration.md +0 -154
  59. data/docs/integration/2_testing.md +0 -287
  60. data/docs/integration/3_rails_integration.md +0 -99
  61. data/docs/yard/Servus/Base.html +0 -1645
  62. data/docs/yard/Servus/Config.html +0 -582
  63. data/docs/yard/Servus/Extensions/Async/Call.html +0 -400
  64. data/docs/yard/Servus/Extensions/Async/Errors/AsyncError.html +0 -140
  65. data/docs/yard/Servus/Extensions/Async/Errors/JobEnqueueError.html +0 -154
  66. data/docs/yard/Servus/Extensions/Async/Errors/ServiceNotFoundError.html +0 -154
  67. data/docs/yard/Servus/Extensions/Async/Errors.html +0 -128
  68. data/docs/yard/Servus/Extensions/Async/Ext.html +0 -119
  69. data/docs/yard/Servus/Extensions/Async/Job.html +0 -310
  70. data/docs/yard/Servus/Extensions/Async.html +0 -141
  71. data/docs/yard/Servus/Extensions.html +0 -117
  72. data/docs/yard/Servus/Generators/ServiceGenerator.html +0 -261
  73. data/docs/yard/Servus/Generators.html +0 -115
  74. data/docs/yard/Servus/Helpers/ControllerHelpers.html +0 -457
  75. data/docs/yard/Servus/Helpers.html +0 -115
  76. data/docs/yard/Servus/Railtie.html +0 -134
  77. data/docs/yard/Servus/Support/Errors/AuthenticationError.html +0 -287
  78. data/docs/yard/Servus/Support/Errors/BadRequestError.html +0 -283
  79. data/docs/yard/Servus/Support/Errors/ForbiddenError.html +0 -284
  80. data/docs/yard/Servus/Support/Errors/InternalServerError.html +0 -283
  81. data/docs/yard/Servus/Support/Errors/NotFoundError.html +0 -284
  82. data/docs/yard/Servus/Support/Errors/ServiceError.html +0 -489
  83. data/docs/yard/Servus/Support/Errors/ServiceUnavailableError.html +0 -290
  84. data/docs/yard/Servus/Support/Errors/UnauthorizedError.html +0 -200
  85. data/docs/yard/Servus/Support/Errors/UnprocessableEntityError.html +0 -288
  86. data/docs/yard/Servus/Support/Errors/ValidationError.html +0 -200
  87. data/docs/yard/Servus/Support/Errors.html +0 -140
  88. data/docs/yard/Servus/Support/Logger.html +0 -856
  89. data/docs/yard/Servus/Support/Rescuer/BlockContext.html +0 -585
  90. data/docs/yard/Servus/Support/Rescuer/CallOverride.html +0 -257
  91. data/docs/yard/Servus/Support/Rescuer/ClassMethods.html +0 -343
  92. data/docs/yard/Servus/Support/Rescuer.html +0 -267
  93. data/docs/yard/Servus/Support/Response.html +0 -574
  94. data/docs/yard/Servus/Support/Validator.html +0 -1150
  95. data/docs/yard/Servus/Support.html +0 -119
  96. data/docs/yard/Servus/Testing/ExampleBuilders.html +0 -523
  97. data/docs/yard/Servus/Testing/ExampleExtractor.html +0 -578
  98. data/docs/yard/Servus/Testing.html +0 -142
  99. data/docs/yard/Servus.html +0 -343
  100. data/docs/yard/_index.html +0 -535
  101. data/docs/yard/class_list.html +0 -54
  102. data/docs/yard/css/common.css +0 -1
  103. data/docs/yard/css/full_list.css +0 -58
  104. data/docs/yard/css/style.css +0 -503
  105. data/docs/yard/file.1_common_patterns.html +0 -154
  106. data/docs/yard/file.1_configuration.html +0 -115
  107. data/docs/yard/file.1_overview.html +0 -142
  108. data/docs/yard/file.1_schema_validation.html +0 -188
  109. data/docs/yard/file.2_architecture.html +0 -157
  110. data/docs/yard/file.2_error_handling.html +0 -190
  111. data/docs/yard/file.2_migration_guide.html +0 -242
  112. data/docs/yard/file.2_testing.html +0 -227
  113. data/docs/yard/file.3_async_execution.html +0 -145
  114. data/docs/yard/file.3_rails_integration.html +0 -160
  115. data/docs/yard/file.3_service_objects.html +0 -191
  116. data/docs/yard/file.4_logging.html +0 -135
  117. data/docs/yard/file.ErrorHandling.html +0 -190
  118. data/docs/yard/file.READme.html +0 -674
  119. data/docs/yard/file.architecture.html +0 -157
  120. data/docs/yard/file.async_execution.html +0 -145
  121. data/docs/yard/file.common_patterns.html +0 -154
  122. data/docs/yard/file.configuration.html +0 -115
  123. data/docs/yard/file.error_handling.html +0 -190
  124. data/docs/yard/file.logging.html +0 -135
  125. data/docs/yard/file.migration_guide.html +0 -242
  126. data/docs/yard/file.overview.html +0 -142
  127. data/docs/yard/file.rails_integration.html +0 -160
  128. data/docs/yard/file.schema_validation.html +0 -188
  129. data/docs/yard/file.service_objects.html +0 -191
  130. data/docs/yard/file.testing.html +0 -227
  131. data/docs/yard/file_list.html +0 -119
  132. data/docs/yard/frames.html +0 -22
  133. data/docs/yard/index.html +0 -674
  134. data/docs/yard/js/app.js +0 -344
  135. data/docs/yard/js/full_list.js +0 -242
  136. data/docs/yard/js/jquery.js +0 -4
  137. data/docs/yard/method_list.html +0 -542
  138. data/docs/yard/top-level-namespace.html +0 -110
@@ -1,257 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: Servus::Support::Rescuer::CallOverride
8
-
9
- &mdash; Servus | Service Object Framework
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../../css/style.css" type="text/css" />
14
-
15
- <link rel="stylesheet" href="../../../css/common.css" type="text/css" />
16
-
17
- <script type="text/javascript">
18
- pathId = "Servus::Support::Rescuer::CallOverride";
19
- relpath = '../../../';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="../../../class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="../../../_index.html">Index (C)</a> &raquo;
40
- <span class='title'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../../Support.html" title="Servus::Support (module)">Support</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Rescuer.html" title="Servus::Support::Rescuer (module)">Rescuer</a></span></span>
41
- &raquo;
42
- <span class="title">CallOverride</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="../../../class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Module: Servus::Support::Rescuer::CallOverride
63
-
64
-
65
- <span class="private note title">Private</span>
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- <dl>
80
- <dt>Defined in:</dt>
81
- <dd>lib/servus/support/rescuer.rb</dd>
82
- </dl>
83
-
84
- </div>
85
-
86
- <h2>Overview</h2><div class="docstring">
87
- <div class="discussion">
88
- <p class="note private">
89
- <strong>This module is part of a private API.</strong>
90
- You should avoid using this module if possible, as it may be removed or be changed in the future.
91
- </p>
92
- <p>Wraps the service&#39;s .call method with error handling logic.</p>
93
-
94
- <p>This module is prepended to the service&#39;s singleton class, allowing it to
95
- intercept calls and add rescue behavior before delegating to the original implementation.</p>
96
-
97
-
98
- </div>
99
- </div>
100
- <div class="tags">
101
-
102
-
103
- </div>
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
- <h2>
112
- Instance Method Summary
113
- <small><a href="#" class="summary_toggle">collapse</a></small>
114
- </h2>
115
-
116
- <ul class="summary">
117
-
118
- <li class="public ">
119
- <span class="summary_signature">
120
-
121
- <a href="#call-instance_method" title="#call (instance method)">#<strong>call</strong>(**args) &#x21d2; Servus::Support::Response </a>
122
-
123
-
124
-
125
- </span>
126
-
127
-
128
-
129
-
130
-
131
-
132
- <span class="private note title">private</span>
133
-
134
-
135
- <span class="summary_desc"><div class='inline'><p>Wraps the service call with automatic error rescue.</p>
136
- </div></span>
137
-
138
- </li>
139
-
140
-
141
- </ul>
142
-
143
-
144
-
145
-
146
- <div id="instance_method_details" class="method_details_list">
147
- <h2>Instance Method Details</h2>
148
-
149
-
150
- <div class="method_details first">
151
- <h3 class="signature first" id="call-instance_method">
152
-
153
- #<strong>call</strong>(**args) &#x21d2; <tt><span class='object_link'><a href="../Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>
154
-
155
-
156
-
157
-
158
-
159
- </h3><div class="docstring">
160
- <div class="discussion">
161
- <p class="note private">
162
- <strong>This method is part of a private API.</strong>
163
- You should avoid using this method if possible, as it may be removed or be changed in the future.
164
- </p>
165
- <p>Wraps the service call with automatic error rescue.</p>
166
-
167
- <p>If rescuable_errors are configured, wraps the call in a rescue block.
168
- Caught exceptions are converted to failure responses using <span class='object_link'>#handle_failure</span>.</p>
169
-
170
-
171
- </div>
172
- </div>
173
- <div class="tags">
174
- <p class="tag_title">Parameters:</p>
175
- <ul class="param">
176
-
177
- <li>
178
-
179
- <span class='name'>args</span>
180
-
181
-
182
- <span class='type'>(<tt>Hash</tt>)</span>
183
-
184
-
185
-
186
- &mdash;
187
- <div class='inline'><p>keyword arguments passed to the service</p>
188
- </div>
189
-
190
- </li>
191
-
192
- </ul>
193
-
194
- <p class="tag_title">Returns:</p>
195
- <ul class="return">
196
-
197
- <li>
198
-
199
-
200
- <span class='type'>(<tt><span class='object_link'><a href="../Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>)</span>
201
-
202
-
203
-
204
- &mdash;
205
- <div class='inline'><p>the service result or failure response</p>
206
- </div>
207
-
208
- </li>
209
-
210
- </ul>
211
-
212
- </div><table class="source_code">
213
- <tr>
214
- <td>
215
- <pre class="lines">
216
-
217
-
218
- 153
219
- 154
220
- 155
221
- 156
222
- 157
223
- 158
224
- 159
225
- 160
226
- 161</pre>
227
- </td>
228
- <td>
229
- <pre class="code"><span class="info file"># File 'lib/servus/support/rescuer.rb', line 153</span>
230
-
231
- <span class='kw'>def</span> <span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
232
- <span class='kw'>return</span> <span class='kw'>super</span> <span class='kw'>if</span> <span class='id identifier rubyid_rescuable_configs'>rescuable_configs</span><span class='period'>.</span><span class='id identifier rubyid_empty?'>empty?</span>
233
-
234
- <span class='kw'>begin</span>
235
- <span class='kw'>super</span>
236
- <span class='kw'>rescue</span> <span class='const'>StandardError</span> <span class='op'>=&gt;</span> <span class='id identifier rubyid_e'>e</span>
237
- <span class='id identifier rubyid_handle_rescued_error'>handle_rescued_error</span><span class='lparen'>(</span><span class='id identifier rubyid_e'>e</span><span class='rparen'>)</span> <span class='op'>||</span> <span class='id identifier rubyid_raise'>raise</span>
238
- <span class='kw'>end</span>
239
- <span class='kw'>end</span></pre>
240
- </td>
241
- </tr>
242
- </table>
243
- </div>
244
-
245
- </div>
246
-
247
- </div>
248
-
249
- <div id="footer">
250
- Generated on Fri Nov 21 00:33:23 2025 by
251
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
252
- 0.9.37 (ruby-3.4.4).
253
- </div>
254
-
255
- </div>
256
- </body>
257
- </html>
@@ -1,343 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>
7
- Module: Servus::Support::Rescuer::ClassMethods
8
-
9
- &mdash; Servus | Service Object Framework
10
-
11
- </title>
12
-
13
- <link rel="stylesheet" href="../../../css/style.css" type="text/css" />
14
-
15
- <link rel="stylesheet" href="../../../css/common.css" type="text/css" />
16
-
17
- <script type="text/javascript">
18
- pathId = "Servus::Support::Rescuer::ClassMethods";
19
- relpath = '../../../';
20
- </script>
21
-
22
-
23
- <script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
24
-
25
- <script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
26
-
27
-
28
- </head>
29
- <body>
30
- <div class="nav_wrap">
31
- <iframe id="nav" src="../../../class_list.html?1"></iframe>
32
- <div id="resizer"></div>
33
- </div>
34
-
35
- <div id="main" tabindex="-1">
36
- <div id="header">
37
- <div id="menu">
38
-
39
- <a href="../../../_index.html">Index (C)</a> &raquo;
40
- <span class='title'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../../Support.html" title="Servus::Support (module)">Support</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Rescuer.html" title="Servus::Support::Rescuer (module)">Rescuer</a></span></span>
41
- &raquo;
42
- <span class="title">ClassMethods</span>
43
-
44
- </div>
45
-
46
- <div id="search">
47
-
48
- <a class="full_list_link" id="class_list_link"
49
- href="../../../class_list.html">
50
-
51
- <svg width="24" height="24">
52
- <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
- <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
- <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
- </svg>
56
- </a>
57
-
58
- </div>
59
- <div class="clear"></div>
60
- </div>
61
-
62
- <div id="content"><h1>Module: Servus::Support::Rescuer::ClassMethods
63
-
64
-
65
-
66
- </h1>
67
- <div class="box_info">
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
- <dl>
80
- <dt>Defined in:</dt>
81
- <dd>lib/servus/support/rescuer.rb</dd>
82
- </dl>
83
-
84
- </div>
85
-
86
- <h2>Overview</h2><div class="docstring">
87
- <div class="discussion">
88
- <p>Class methods for rescue_from</p>
89
-
90
-
91
- </div>
92
- </div>
93
- <div class="tags">
94
-
95
-
96
- </div>
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
- <h2>
105
- Instance Method Summary
106
- <small><a href="#" class="summary_toggle">collapse</a></small>
107
- </h2>
108
-
109
- <ul class="summary">
110
-
111
- <li class="public ">
112
- <span class="summary_signature">
113
-
114
- <a href="#rescue_from-instance_method" title="#rescue_from (instance method)">#<strong>rescue_from</strong>(*errors, use: Servus::Support::Errors::ServiceError) {|exception| ... } &#x21d2; Object </a>
115
-
116
-
117
-
118
- </span>
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
- <span class="summary_desc"><div class='inline'><p>Configures automatic error handling for the service.</p>
129
- </div></span>
130
-
131
- </li>
132
-
133
-
134
- </ul>
135
-
136
-
137
-
138
-
139
- <div id="instance_method_details" class="method_details_list">
140
- <h2>Instance Method Details</h2>
141
-
142
-
143
- <div class="method_details first">
144
- <h3 class="signature first" id="rescue_from-instance_method">
145
-
146
- #<strong>rescue_from</strong>(*errors, use: Servus::Support::Errors::ServiceError) {|exception| ... } &#x21d2; <tt>Object</tt>
147
-
148
-
149
-
150
-
151
-
152
- </h3><div class="docstring">
153
- <div class="discussion">
154
- <p>Configures automatic error handling for the service.</p>
155
-
156
- <p>Declares which exception classes should be automatically rescued and converted
157
- to failure responses. Without a block, exceptions are wrapped in the specified
158
- ServiceError type with a formatted message including the original exception details.</p>
159
-
160
- <p>When a block is provided, it receives the exception and must return either
161
- <code>success(data)</code> or <code>failure(message, type:)</code> to create the response.</p>
162
-
163
-
164
- </div>
165
- </div>
166
- <div class="tags">
167
-
168
- <div class="examples">
169
- <h4 class="tag_title">Examples:</h4>
170
-
171
-
172
- <h5 class="example_title"><div class='inline'><p>Basic usage with default error type:</p>
173
- </div></h5>
174
-
175
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>TestService</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Base.html" title="Servus::Base (class)">Base</a></span></span>
176
- <span class='id identifier rubyid_rescue_from'>rescue_from</span> <span class='const'>Net</span><span class='op'>::</span><span class='const'>HTTPError</span><span class='comma'>,</span> <span class='const'>Timeout</span><span class='op'>::</span><span class='const'>Error</span><span class='comma'>,</span> <span class='label'>use:</span> <span class='const'>ServiceUnavailableError</span>
177
- <span class='kw'>end</span></code></pre>
178
-
179
-
180
- <h5 class="example_title"><div class='inline'><p>Custom error handling with block:</p>
181
- </div></h5>
182
-
183
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>TestService</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Base.html" title="Servus::Base (class)">Base</a></span></span>
184
- <span class='id identifier rubyid_rescue_from'>rescue_from</span> <span class='const'>ActiveRecord</span><span class='op'>::</span><span class='const'>RecordInvalid</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_exception'>exception</span><span class='op'>|</span>
185
- <span class='id identifier rubyid_failure'>failure</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Validation failed: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_exception'>exception</span><span class='period'>.</span><span class='id identifier rubyid_message'>message</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>ValidationError</span><span class='rparen'>)</span>
186
- <span class='kw'>end</span>
187
- <span class='kw'>end</span></code></pre>
188
-
189
-
190
- <h5 class="example_title"><div class='inline'><p>Recovering from errors with success:</p>
191
- </div></h5>
192
-
193
- <pre class="example code"><code><span class='kw'>class</span> <span class='const'>TestService</span> <span class='op'>&lt;</span> <span class='const'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Base.html" title="Servus::Base (class)">Base</a></span></span>
194
- <span class='id identifier rubyid_rescue_from'>rescue_from</span> <span class='const'>Stripe</span><span class='op'>::</span><span class='const'>CardError</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_exception'>exception</span><span class='op'>|</span>
195
- <span class='kw'>if</span> <span class='id identifier rubyid_exception'>exception</span><span class='period'>.</span><span class='id identifier rubyid_code'>code</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>card_declined</span><span class='tstring_end'>&#39;</span></span>
196
- <span class='id identifier rubyid_failure'>failure</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Card declined</span><span class='tstring_end'>&quot;</span></span><span class='comma'>,</span> <span class='label'>type:</span> <span class='const'>BadRequestError</span><span class='rparen'>)</span>
197
- <span class='kw'>else</span>
198
- <span class='id identifier rubyid_success'>success</span><span class='lparen'>(</span><span class='label'>recovered:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='label'>fallback_used:</span> <span class='kw'>true</span><span class='rparen'>)</span>
199
- <span class='kw'>end</span>
200
- <span class='kw'>end</span>
201
- <span class='kw'>end</span></code></pre>
202
-
203
- </div>
204
- <p class="tag_title">Parameters:</p>
205
- <ul class="param">
206
-
207
- <li>
208
-
209
- <span class='name'>errors</span>
210
-
211
-
212
- <span class='type'>(<tt>Class&lt;StandardError&gt;</tt>)</span>
213
-
214
-
215
-
216
- &mdash;
217
- <div class='inline'><p>One or more exception classes to rescue from</p>
218
- </div>
219
-
220
- </li>
221
-
222
- <li>
223
-
224
- <span class='name'>use</span>
225
-
226
-
227
- <span class='type'>(<tt>Class&lt;<span class='object_link'><a href="../Errors/ServiceError.html" title="Servus::Support::Errors::ServiceError (class)">Servus::Support::Errors::ServiceError</a></span>&gt;</tt>)</span>
228
-
229
-
230
- <em class="default">(defaults to: <tt>Servus::Support::Errors::ServiceError</tt>)</em>
231
-
232
-
233
- &mdash;
234
- <div class='inline'><p>Error class to use when wrapping exceptions
235
- (only used without block)</p>
236
- </div>
237
-
238
- </li>
239
-
240
- </ul>
241
-
242
- <p class="tag_title">Yields:</p>
243
- <ul class="yield">
244
-
245
- <li>
246
-
247
-
248
- <span class='type'>(<tt>exception</tt>)</span>
249
-
250
-
251
-
252
- &mdash;
253
- <div class='inline'><p>Optional block for custom error handling</p>
254
- </div>
255
-
256
- </li>
257
-
258
- </ul>
259
- <p class="tag_title">Yield Parameters:</p>
260
- <ul class="yieldparam">
261
-
262
- <li>
263
-
264
- <span class='name'>exception</span>
265
-
266
-
267
- <span class='type'>(<tt>StandardError</tt>)</span>
268
-
269
-
270
-
271
- &mdash;
272
- <div class='inline'><p>The caught exception</p>
273
- </div>
274
-
275
- </li>
276
-
277
- </ul>
278
- <p class="tag_title">Yield Returns:</p>
279
- <ul class="yieldreturn">
280
-
281
- <li>
282
-
283
-
284
- <span class='type'>(<tt><span class='object_link'><a href="../Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>)</span>
285
-
286
-
287
-
288
- &mdash;
289
- <div class='inline'><p>Must return success() or failure() response</p>
290
- </div>
291
-
292
- </li>
293
-
294
- </ul>
295
-
296
- </div><table class="source_code">
297
- <tr>
298
- <td>
299
- <pre class="lines">
300
-
301
-
302
- 125
303
- 126
304
- 127
305
- 128
306
- 129
307
- 130
308
- 131
309
- 132
310
- 133
311
- 134</pre>
312
- </td>
313
- <td>
314
- <pre class="code"><span class="info file"># File 'lib/servus/support/rescuer.rb', line 125</span>
315
-
316
- <span class='kw'>def</span> <span class='id identifier rubyid_rescue_from'>rescue_from</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_errors'>errors</span><span class='comma'>,</span> <span class='label'>use:</span> <span class='const'><span class='object_link'><a href="../../../Servus.html" title="Servus (module)">Servus</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Support.html" title="Servus::Support (module)">Support</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Errors.html" title="Servus::Support::Errors (module)">Errors</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../Errors/ServiceError.html" title="Servus::Support::Errors::ServiceError (class)">ServiceError</a></span></span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
317
- <span class='id identifier rubyid_config'>config</span> <span class='op'>=</span> <span class='lbrace'>{</span>
318
- <span class='label'>errors:</span> <span class='id identifier rubyid_errors'>errors</span><span class='comma'>,</span>
319
- <span class='label'>error_type:</span> <span class='id identifier rubyid_use'>use</span><span class='comma'>,</span>
320
- <span class='label'>handler:</span> <span class='id identifier rubyid_block'>block</span>
321
- <span class='rbrace'>}</span>
322
-
323
- <span class='comment'># Add to rescuable_configs array
324
- </span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_rescuable_configs'>rescuable_configs</span> <span class='op'>=</span> <span class='id identifier rubyid_rescuable_configs'>rescuable_configs</span> <span class='op'>+</span> <span class='lbracket'>[</span><span class='id identifier rubyid_config'>config</span><span class='rbracket'>]</span>
325
- <span class='kw'>end</span></pre>
326
- </td>
327
- </tr>
328
- </table>
329
- </div>
330
-
331
- </div>
332
-
333
- </div>
334
-
335
- <div id="footer">
336
- Generated on Fri Nov 21 00:33:23 2025 by
337
- <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
338
- 0.9.37 (ruby-3.4.4).
339
- </div>
340
-
341
- </div>
342
- </body>
343
- </html>