servus 0.1.2 → 0.1.4
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/.yardopts +6 -0
- data/CHANGELOG.md +8 -1
- data/IDEAS.md +5 -0
- data/READme.md +147 -42
- data/Rakefile +33 -0
- data/builds/servus-0.1.2.gem +0 -0
- data/builds/servus-0.1.3.gem +0 -0
- data/builds/servus-0.1.4.gem +0 -0
- data/docs/core/1_overview.md +77 -0
- data/docs/core/2_architecture.md +92 -0
- data/docs/core/3_service_objects.md +121 -0
- data/docs/features/1_schema_validation.md +119 -0
- data/docs/features/2_error_handling.md +121 -0
- data/docs/features/3_async_execution.md +81 -0
- data/docs/features/4_logging.md +64 -0
- data/docs/guides/1_common_patterns.md +90 -0
- data/docs/guides/2_migration_guide.md +175 -0
- data/docs/integration/1_configuration.md +51 -0
- data/docs/integration/2_testing.md +164 -0
- data/docs/integration/3_rails_integration.md +99 -0
- data/docs/yard/Servus/Base.html +1645 -0
- data/docs/yard/Servus/Config.html +582 -0
- data/docs/yard/Servus/Extensions/Async/Call.html +400 -0
- data/docs/yard/Servus/Extensions/Async/Errors/AsyncError.html +140 -0
- data/docs/yard/Servus/Extensions/Async/Errors/JobEnqueueError.html +154 -0
- data/docs/yard/Servus/Extensions/Async/Errors/ServiceNotFoundError.html +154 -0
- data/docs/yard/Servus/Extensions/Async/Errors.html +128 -0
- data/docs/yard/Servus/Extensions/Async/Ext.html +119 -0
- data/docs/yard/Servus/Extensions/Async/Job.html +310 -0
- data/docs/yard/Servus/Extensions/Async.html +141 -0
- data/docs/yard/Servus/Extensions.html +117 -0
- data/docs/yard/Servus/Generators/ServiceGenerator.html +261 -0
- data/docs/yard/Servus/Generators.html +115 -0
- data/docs/yard/Servus/Helpers/ControllerHelpers.html +457 -0
- data/docs/yard/Servus/Helpers.html +115 -0
- data/docs/yard/Servus/Railtie.html +134 -0
- data/docs/yard/Servus/Support/Errors/AuthenticationError.html +287 -0
- data/docs/yard/Servus/Support/Errors/BadRequestError.html +283 -0
- data/docs/yard/Servus/Support/Errors/ForbiddenError.html +284 -0
- data/docs/yard/Servus/Support/Errors/InternalServerError.html +283 -0
- data/docs/yard/Servus/Support/Errors/NotFoundError.html +284 -0
- data/docs/yard/Servus/Support/Errors/ServiceError.html +489 -0
- data/docs/yard/Servus/Support/Errors/ServiceUnavailableError.html +290 -0
- data/docs/yard/Servus/Support/Errors/UnauthorizedError.html +200 -0
- data/docs/yard/Servus/Support/Errors/UnprocessableEntityError.html +288 -0
- data/docs/yard/Servus/Support/Errors/ValidationError.html +200 -0
- data/docs/yard/Servus/Support/Errors.html +140 -0
- data/docs/yard/Servus/Support/Logger.html +856 -0
- data/docs/yard/Servus/Support/Rescuer/BlockContext.html +585 -0
- data/docs/yard/Servus/Support/Rescuer/CallOverride.html +257 -0
- data/docs/yard/Servus/Support/Rescuer/ClassMethods.html +343 -0
- data/docs/yard/Servus/Support/Rescuer.html +267 -0
- data/docs/yard/Servus/Support/Response.html +574 -0
- data/docs/yard/Servus/Support/Validator.html +1150 -0
- data/docs/yard/Servus/Support.html +119 -0
- data/docs/yard/Servus/Testing/ExampleBuilders.html +523 -0
- data/docs/yard/Servus/Testing/ExampleExtractor.html +578 -0
- data/docs/yard/Servus/Testing.html +142 -0
- data/docs/yard/Servus.html +343 -0
- data/docs/yard/_index.html +535 -0
- data/docs/yard/class_list.html +54 -0
- data/docs/yard/css/common.css +1 -0
- data/docs/yard/css/full_list.css +58 -0
- data/docs/yard/css/style.css +503 -0
- data/docs/yard/file.1_common_patterns.html +154 -0
- data/docs/yard/file.1_configuration.html +115 -0
- data/docs/yard/file.1_overview.html +142 -0
- data/docs/yard/file.1_schema_validation.html +188 -0
- data/docs/yard/file.2_architecture.html +157 -0
- data/docs/yard/file.2_error_handling.html +190 -0
- data/docs/yard/file.2_migration_guide.html +242 -0
- data/docs/yard/file.2_testing.html +227 -0
- data/docs/yard/file.3_async_execution.html +145 -0
- data/docs/yard/file.3_rails_integration.html +160 -0
- data/docs/yard/file.3_service_objects.html +191 -0
- data/docs/yard/file.4_logging.html +135 -0
- data/docs/yard/file.ErrorHandling.html +190 -0
- data/docs/yard/file.READme.html +674 -0
- data/docs/yard/file.architecture.html +157 -0
- data/docs/yard/file.async_execution.html +145 -0
- data/docs/yard/file.common_patterns.html +154 -0
- data/docs/yard/file.configuration.html +115 -0
- data/docs/yard/file.error_handling.html +190 -0
- data/docs/yard/file.logging.html +135 -0
- data/docs/yard/file.migration_guide.html +242 -0
- data/docs/yard/file.overview.html +142 -0
- data/docs/yard/file.rails_integration.html +160 -0
- data/docs/yard/file.schema_validation.html +188 -0
- data/docs/yard/file.service_objects.html +191 -0
- data/docs/yard/file.testing.html +227 -0
- data/docs/yard/file_list.html +119 -0
- data/docs/yard/frames.html +22 -0
- data/docs/yard/index.html +674 -0
- data/docs/yard/js/app.js +344 -0
- data/docs/yard/js/full_list.js +242 -0
- data/docs/yard/js/jquery.js +4 -0
- data/docs/yard/method_list.html +542 -0
- data/docs/yard/top-level-namespace.html +110 -0
- data/lib/generators/servus/service/service_generator.rb +64 -1
- data/lib/generators/servus/service/templates/service.rb.erb +1 -1
- data/lib/servus/base.rb +258 -57
- data/lib/servus/config.rb +58 -12
- data/lib/servus/extensions/async/call.rb +50 -18
- data/lib/servus/extensions/async/errors.rb +23 -3
- data/lib/servus/extensions/async/ext.rb +10 -2
- data/lib/servus/extensions/async/job.rb +32 -11
- data/lib/servus/helpers/controller_helpers.rb +73 -37
- data/lib/servus/support/errors.rb +135 -45
- data/lib/servus/support/rescuer.rb +189 -36
- data/lib/servus/support/response.rb +49 -7
- data/lib/servus/support/validator.rb +120 -19
- data/lib/servus/testing/example_builders.rb +133 -0
- data/lib/servus/testing/example_extractor.rb +309 -0
- data/lib/servus/testing.rb +17 -0
- data/lib/servus/version.rb +1 -1
- metadata +118 -19
|
@@ -0,0 +1,1150 @@
|
|
|
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
|
+
Class: Servus::Support::Validator
|
|
8
|
+
|
|
9
|
+
— 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::Validator";
|
|
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 (V)</a> »
|
|
40
|
+
<span class='title'><span class='object_link'><a href="../../Servus.html" title="Servus (module)">Servus</a></span></span> » <span class='title'><span class='object_link'><a href="../Support.html" title="Servus::Support (module)">Support</a></span></span>
|
|
41
|
+
»
|
|
42
|
+
<span class="title">Validator</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>Class: Servus::Support::Validator
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
</h1>
|
|
67
|
+
<div class="box_info">
|
|
68
|
+
|
|
69
|
+
<dl>
|
|
70
|
+
<dt>Inherits:</dt>
|
|
71
|
+
<dd>
|
|
72
|
+
<span class="inheritName">Object</span>
|
|
73
|
+
|
|
74
|
+
<ul class="fullTree">
|
|
75
|
+
<li>Object</li>
|
|
76
|
+
|
|
77
|
+
<li class="next">Servus::Support::Validator</li>
|
|
78
|
+
|
|
79
|
+
</ul>
|
|
80
|
+
<a href="#" class="inheritanceTree">show all</a>
|
|
81
|
+
|
|
82
|
+
</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
<dl>
|
|
96
|
+
<dt>Defined in:</dt>
|
|
97
|
+
<dd>lib/servus/support/validator.rb</dd>
|
|
98
|
+
</dl>
|
|
99
|
+
|
|
100
|
+
</div>
|
|
101
|
+
|
|
102
|
+
<h2>Overview</h2><div class="docstring">
|
|
103
|
+
<div class="discussion">
|
|
104
|
+
<p>Handles JSON Schema validation for service arguments and results.</p>
|
|
105
|
+
|
|
106
|
+
<p>The Validator class provides automatic validation of service inputs and outputs
|
|
107
|
+
against JSON Schema definitions. Schemas can be defined as inline constants
|
|
108
|
+
(ARGUMENTS_SCHEMA, RESULT_SCHEMA) or as external JSON files.</p>
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
</div>
|
|
112
|
+
</div>
|
|
113
|
+
<div class="tags">
|
|
114
|
+
|
|
115
|
+
<div class="examples">
|
|
116
|
+
<h4 class="tag_title">Examples:</h4>
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
<h5 class="example_title"><div class='inline'><p>Inline schema validation</p>
|
|
120
|
+
</div></h5>
|
|
121
|
+
|
|
122
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>MyService</span> <span class='op'><</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>
|
|
123
|
+
<span class='const'>ARGUMENTS_SCHEMA</span> <span class='op'>=</span> <span class='lbrace'>{</span>
|
|
124
|
+
<span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>object</span><span class='tstring_end'>"</span></span><span class='comma'>,</span>
|
|
125
|
+
<span class='label'>required:</span> <span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>user_id</span><span class='tstring_end'>"</span></span><span class='rbracket'>]</span><span class='comma'>,</span>
|
|
126
|
+
<span class='label'>properties:</span> <span class='lbrace'>{</span>
|
|
127
|
+
<span class='label'>user_id:</span> <span class='lbrace'>{</span> <span class='label'>type:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>integer</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span>
|
|
128
|
+
<span class='rbrace'>}</span>
|
|
129
|
+
<span class='rbrace'>}</span>
|
|
130
|
+
<span class='kw'>end</span></code></pre>
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
<h5 class="example_title"><div class='inline'><p>File-based schema validation</p>
|
|
134
|
+
</div></h5>
|
|
135
|
+
|
|
136
|
+
<pre class="example code"><code><span class='comment'># app/schemas/services/my_service/arguments.json
|
|
137
|
+
</span><span class='comment'># { "type": "object", "required": ["user_id"], ... }</span></code></pre>
|
|
138
|
+
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
<p class="tag_title">See Also:</p>
|
|
143
|
+
<ul class="see">
|
|
144
|
+
|
|
145
|
+
<li><a href="https://json-schema.org/specification.html" target="_parent" title="https://json-schema.org/specification.html">https://json-schema.org/specification.html</a></li>
|
|
146
|
+
|
|
147
|
+
</ul>
|
|
148
|
+
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
<h2>
|
|
158
|
+
Class Method Summary
|
|
159
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
160
|
+
</h2>
|
|
161
|
+
|
|
162
|
+
<ul class="summary">
|
|
163
|
+
|
|
164
|
+
<li class="public ">
|
|
165
|
+
<span class="summary_signature">
|
|
166
|
+
|
|
167
|
+
<a href="#cache-class_method" title="cache (class method)">.<strong>cache</strong> ⇒ Hash </a>
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
</span>
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
<span class="private note title">private</span>
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
<span class="summary_desc"><div class='inline'><p>Returns the current schema cache.</p>
|
|
182
|
+
</div></span>
|
|
183
|
+
|
|
184
|
+
</li>
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
<li class="public ">
|
|
188
|
+
<span class="summary_signature">
|
|
189
|
+
|
|
190
|
+
<a href="#clear_cache!-class_method" title="clear_cache! (class method)">.<strong>clear_cache!</strong> ⇒ Hash </a>
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
</span>
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
<span class="summary_desc"><div class='inline'><p>Clears the schema cache.</p>
|
|
205
|
+
</div></span>
|
|
206
|
+
|
|
207
|
+
</li>
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
<li class="public ">
|
|
211
|
+
<span class="summary_signature">
|
|
212
|
+
|
|
213
|
+
<a href="#fetch_schema_from_sources-class_method" title="fetch_schema_from_sources (class method)">.<strong>fetch_schema_from_sources</strong>(dsl_schema, inline_schema_constant, schema_path) ⇒ Hash<sup>?</sup> </a>
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
</span>
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
<span class="private note title">private</span>
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
<span class="summary_desc"><div class='inline'><p>Fetches schema from DSL, inline constant, or file.</p>
|
|
228
|
+
</div></span>
|
|
229
|
+
|
|
230
|
+
</li>
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
<li class="public ">
|
|
234
|
+
<span class="summary_signature">
|
|
235
|
+
|
|
236
|
+
<a href="#load_schema-class_method" title="load_schema (class method)">.<strong>load_schema</strong>(service_class, type) ⇒ Hash<sup>?</sup> </a>
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
</span>
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
<span class="private note title">private</span>
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
<span class="summary_desc"><div class='inline'><p>Loads and caches a schema for a service.</p>
|
|
251
|
+
</div></span>
|
|
252
|
+
|
|
253
|
+
</li>
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
<li class="public ">
|
|
257
|
+
<span class="summary_signature">
|
|
258
|
+
|
|
259
|
+
<a href="#parse_service_namespace-class_method" title="parse_service_namespace (class method)">.<strong>parse_service_namespace</strong>(service_class) ⇒ String </a>
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
</span>
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
<span class="private note title">private</span>
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
<span class="summary_desc"><div class='inline'><p>Converts service class name to file path namespace.</p>
|
|
274
|
+
</div></span>
|
|
275
|
+
|
|
276
|
+
</li>
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
<li class="public ">
|
|
280
|
+
<span class="summary_signature">
|
|
281
|
+
|
|
282
|
+
<a href="#validate_arguments!-class_method" title="validate_arguments! (class method)">.<strong>validate_arguments!</strong>(service_class, args) ⇒ Boolean </a>
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
</span>
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
<span class="private note title">private</span>
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
<span class="summary_desc"><div class='inline'><p>Validates service arguments against the ARGUMENTS_SCHEMA.</p>
|
|
297
|
+
</div></span>
|
|
298
|
+
|
|
299
|
+
</li>
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
<li class="public ">
|
|
303
|
+
<span class="summary_signature">
|
|
304
|
+
|
|
305
|
+
<a href="#validate_result!-class_method" title="validate_result! (class method)">.<strong>validate_result!</strong>(service_class, result) ⇒ Servus::Support::Response </a>
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
</span>
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
<span class="private note title">private</span>
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
<span class="summary_desc"><div class='inline'><p>Validates service result data against the RESULT_SCHEMA.</p>
|
|
320
|
+
</div></span>
|
|
321
|
+
|
|
322
|
+
</li>
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
</ul>
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
<div id="class_method_details" class="method_details_list">
|
|
331
|
+
<h2>Class Method Details</h2>
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
<div class="method_details first">
|
|
335
|
+
<h3 class="signature first" id="cache-class_method">
|
|
336
|
+
|
|
337
|
+
.<strong>cache</strong> ⇒ <tt>Hash</tt>
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
</h3><div class="docstring">
|
|
344
|
+
<div class="discussion">
|
|
345
|
+
<p class="note private">
|
|
346
|
+
<strong>This method is part of a private API.</strong>
|
|
347
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
348
|
+
</p>
|
|
349
|
+
<p>Returns the current schema cache.</p>
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
</div>
|
|
353
|
+
</div>
|
|
354
|
+
<div class="tags">
|
|
355
|
+
|
|
356
|
+
<p class="tag_title">Returns:</p>
|
|
357
|
+
<ul class="return">
|
|
358
|
+
|
|
359
|
+
<li>
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
—
|
|
367
|
+
<div class='inline'><p>cache mapping schema paths to loaded schemas</p>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
</li>
|
|
371
|
+
|
|
372
|
+
</ul>
|
|
373
|
+
|
|
374
|
+
</div><table class="source_code">
|
|
375
|
+
<tr>
|
|
376
|
+
<td>
|
|
377
|
+
<pre class="lines">
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
152
|
|
381
|
+
153
|
|
382
|
+
154</pre>
|
|
383
|
+
</td>
|
|
384
|
+
<td>
|
|
385
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 152</span>
|
|
386
|
+
|
|
387
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_cache'>cache</span>
|
|
388
|
+
<span class='ivar'>@schema_cache</span>
|
|
389
|
+
<span class='kw'>end</span></pre>
|
|
390
|
+
</td>
|
|
391
|
+
</tr>
|
|
392
|
+
</table>
|
|
393
|
+
</div>
|
|
394
|
+
|
|
395
|
+
<div class="method_details ">
|
|
396
|
+
<h3 class="signature " id="clear_cache!-class_method">
|
|
397
|
+
|
|
398
|
+
.<strong>clear_cache!</strong> ⇒ <tt>Hash</tt>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
</h3><div class="docstring">
|
|
405
|
+
<div class="discussion">
|
|
406
|
+
<p>Clears the schema cache.</p>
|
|
407
|
+
|
|
408
|
+
<p>Useful in development when schema files are modified, or in tests
|
|
409
|
+
to ensure fresh schema loading between test cases.</p>
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
</div>
|
|
413
|
+
</div>
|
|
414
|
+
<div class="tags">
|
|
415
|
+
|
|
416
|
+
<div class="examples">
|
|
417
|
+
<h4 class="tag_title">Examples:</h4>
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
<h5 class="example_title"><div class='inline'><p>In a test suite</p>
|
|
421
|
+
</div></h5>
|
|
422
|
+
|
|
423
|
+
<pre class="example code"><code><span class='id identifier rubyid_before'>before</span><span class='lparen'>(</span><span class='symbol'>:each</span><span class='rparen'>)</span> <span class='kw'>do</span>
|
|
424
|
+
<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="" title="Servus::Support::Validator (class)">Validator</a></span></span><span class='period'>.</span><span class='id identifier rubyid_clear_cache!'>clear_cache!</span>
|
|
425
|
+
<span class='kw'>end</span></code></pre>
|
|
426
|
+
|
|
427
|
+
</div>
|
|
428
|
+
|
|
429
|
+
<p class="tag_title">Returns:</p>
|
|
430
|
+
<ul class="return">
|
|
431
|
+
|
|
432
|
+
<li>
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
—
|
|
440
|
+
<div class='inline'><p>empty hash</p>
|
|
441
|
+
</div>
|
|
442
|
+
|
|
443
|
+
</li>
|
|
444
|
+
|
|
445
|
+
</ul>
|
|
446
|
+
|
|
447
|
+
</div><table class="source_code">
|
|
448
|
+
<tr>
|
|
449
|
+
<td>
|
|
450
|
+
<pre class="lines">
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
144
|
|
454
|
+
145
|
|
455
|
+
146</pre>
|
|
456
|
+
</td>
|
|
457
|
+
<td>
|
|
458
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 144</span>
|
|
459
|
+
|
|
460
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_clear_cache!'>clear_cache!</span>
|
|
461
|
+
<span class='ivar'>@schema_cache</span> <span class='op'>=</span> <span class='lbrace'>{</span><span class='rbrace'>}</span>
|
|
462
|
+
<span class='kw'>end</span></pre>
|
|
463
|
+
</td>
|
|
464
|
+
</tr>
|
|
465
|
+
</table>
|
|
466
|
+
</div>
|
|
467
|
+
|
|
468
|
+
<div class="method_details ">
|
|
469
|
+
<h3 class="signature " id="fetch_schema_from_sources-class_method">
|
|
470
|
+
|
|
471
|
+
.<strong>fetch_schema_from_sources</strong>(dsl_schema, inline_schema_constant, schema_path) ⇒ <tt>Hash</tt><sup>?</sup>
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
477
|
+
</h3><div class="docstring">
|
|
478
|
+
<div class="discussion">
|
|
479
|
+
<p class="note private">
|
|
480
|
+
<strong>This method is part of a private API.</strong>
|
|
481
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
482
|
+
</p>
|
|
483
|
+
<p>Fetches schema from DSL, inline constant, or file.</p>
|
|
484
|
+
|
|
485
|
+
<p>Implements the schema resolution precedence:</p>
|
|
486
|
+
|
|
487
|
+
<ol>
|
|
488
|
+
<li>DSL-defined schema (if provided)</li>
|
|
489
|
+
<li>Inline constant (if provided)</li>
|
|
490
|
+
<li>File at schema_path (if exists)</li>
|
|
491
|
+
<li>nil (no schema found)</li>
|
|
492
|
+
</ol>
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
</div>
|
|
496
|
+
</div>
|
|
497
|
+
<div class="tags">
|
|
498
|
+
<p class="tag_title">Parameters:</p>
|
|
499
|
+
<ul class="param">
|
|
500
|
+
|
|
501
|
+
<li>
|
|
502
|
+
|
|
503
|
+
<span class='name'>dsl_schema</span>
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
<span class='type'>(<tt>Hash</tt>, <tt>nil</tt>)</span>
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
—
|
|
511
|
+
<div class='inline'><p>schema from DSL method (e.g., schema arguments: Hash)</p>
|
|
512
|
+
</div>
|
|
513
|
+
|
|
514
|
+
</li>
|
|
515
|
+
|
|
516
|
+
<li>
|
|
517
|
+
|
|
518
|
+
<span class='name'>inline_schema_constant</span>
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
<span class='type'>(<tt>Hash</tt>, <tt>nil</tt>)</span>
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
—
|
|
526
|
+
<div class='inline'><p>inline schema constant (e.g., ARGUMENTS_SCHEMA)</p>
|
|
527
|
+
</div>
|
|
528
|
+
|
|
529
|
+
</li>
|
|
530
|
+
|
|
531
|
+
<li>
|
|
532
|
+
|
|
533
|
+
<span class='name'>schema_path</span>
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
—
|
|
541
|
+
<div class='inline'><p>file path to external schema JSON</p>
|
|
542
|
+
</div>
|
|
543
|
+
|
|
544
|
+
</li>
|
|
545
|
+
|
|
546
|
+
</ul>
|
|
547
|
+
|
|
548
|
+
<p class="tag_title">Returns:</p>
|
|
549
|
+
<ul class="return">
|
|
550
|
+
|
|
551
|
+
<li>
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
<span class='type'>(<tt>Hash</tt>, <tt>nil</tt>)</span>
|
|
555
|
+
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
—
|
|
559
|
+
<div class='inline'><p>schema with indifferent access, or nil if not found</p>
|
|
560
|
+
</div>
|
|
561
|
+
|
|
562
|
+
</li>
|
|
563
|
+
|
|
564
|
+
</ul>
|
|
565
|
+
|
|
566
|
+
</div><table class="source_code">
|
|
567
|
+
<tr>
|
|
568
|
+
<td>
|
|
569
|
+
<pre class="lines">
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
170
|
|
573
|
+
171
|
|
574
|
+
172
|
|
575
|
+
173
|
|
576
|
+
174
|
|
577
|
+
175
|
|
578
|
+
176
|
|
579
|
+
177
|
|
580
|
+
178</pre>
|
|
581
|
+
</td>
|
|
582
|
+
<td>
|
|
583
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 170</span>
|
|
584
|
+
|
|
585
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_fetch_schema_from_sources'>fetch_schema_from_sources</span><span class='lparen'>(</span><span class='id identifier rubyid_dsl_schema'>dsl_schema</span><span class='comma'>,</span> <span class='id identifier rubyid_inline_schema_constant'>inline_schema_constant</span><span class='comma'>,</span> <span class='id identifier rubyid_schema_path'>schema_path</span><span class='rparen'>)</span>
|
|
586
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_dsl_schema'>dsl_schema</span>
|
|
587
|
+
<span class='id identifier rubyid_dsl_schema'>dsl_schema</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span>
|
|
588
|
+
<span class='kw'>elsif</span> <span class='id identifier rubyid_inline_schema_constant'>inline_schema_constant</span>
|
|
589
|
+
<span class='id identifier rubyid_inline_schema_constant'>inline_schema_constant</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span>
|
|
590
|
+
<span class='kw'>elsif</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_exist?'>exist?</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rparen'>)</span>
|
|
591
|
+
<span class='const'>JSON</span><span class='period'>.</span><span class='id identifier rubyid_load_file'>load_file</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_with_indifferent_access'>with_indifferent_access</span>
|
|
592
|
+
<span class='kw'>end</span>
|
|
593
|
+
<span class='kw'>end</span></pre>
|
|
594
|
+
</td>
|
|
595
|
+
</tr>
|
|
596
|
+
</table>
|
|
597
|
+
</div>
|
|
598
|
+
|
|
599
|
+
<div class="method_details ">
|
|
600
|
+
<h3 class="signature " id="load_schema-class_method">
|
|
601
|
+
|
|
602
|
+
.<strong>load_schema</strong>(service_class, type) ⇒ <tt>Hash</tt><sup>?</sup>
|
|
603
|
+
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
</h3><div class="docstring">
|
|
609
|
+
<div class="discussion">
|
|
610
|
+
<p class="note private">
|
|
611
|
+
<strong>This method is part of a private API.</strong>
|
|
612
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
613
|
+
</p>
|
|
614
|
+
<p>Loads and caches a schema for a service.</p>
|
|
615
|
+
|
|
616
|
+
<p>Implements a three-tier lookup strategy:</p>
|
|
617
|
+
|
|
618
|
+
<ol>
|
|
619
|
+
<li>Check for schema defined via DSL method (service_class.arguments_schema/result_schema)</li>
|
|
620
|
+
<li>Check for inline constant (ARGUMENTS_SCHEMA or RESULT_SCHEMA)</li>
|
|
621
|
+
<li>Fall back to JSON file in app/schemas/services/namespace/type.json</li>
|
|
622
|
+
</ol>
|
|
623
|
+
|
|
624
|
+
<p>Schemas are cached after first load for performance.</p>
|
|
625
|
+
|
|
626
|
+
<p>rubocop:disable Metrics/MethodLength</p>
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
</div>
|
|
630
|
+
</div>
|
|
631
|
+
<div class="tags">
|
|
632
|
+
<p class="tag_title">Parameters:</p>
|
|
633
|
+
<ul class="param">
|
|
634
|
+
|
|
635
|
+
<li>
|
|
636
|
+
|
|
637
|
+
<span class='name'>service_class</span>
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
644
|
+
—
|
|
645
|
+
<div class='inline'><p>the service class</p>
|
|
646
|
+
</div>
|
|
647
|
+
|
|
648
|
+
</li>
|
|
649
|
+
|
|
650
|
+
<li>
|
|
651
|
+
|
|
652
|
+
<span class='name'>type</span>
|
|
653
|
+
|
|
654
|
+
|
|
655
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
659
|
+
—
|
|
660
|
+
<div class='inline'><p>schema type ("arguments" or "result")</p>
|
|
661
|
+
</div>
|
|
662
|
+
|
|
663
|
+
</li>
|
|
664
|
+
|
|
665
|
+
</ul>
|
|
666
|
+
|
|
667
|
+
<p class="tag_title">Returns:</p>
|
|
668
|
+
<ul class="return">
|
|
669
|
+
|
|
670
|
+
<li>
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
<span class='type'>(<tt>Hash</tt>, <tt>nil</tt>)</span>
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
—
|
|
678
|
+
<div class='inline'><p>the schema hash, or nil if no schema found</p>
|
|
679
|
+
</div>
|
|
680
|
+
|
|
681
|
+
</li>
|
|
682
|
+
|
|
683
|
+
</ul>
|
|
684
|
+
|
|
685
|
+
</div><table class="source_code">
|
|
686
|
+
<tr>
|
|
687
|
+
<td>
|
|
688
|
+
<pre class="lines">
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
108
|
|
692
|
+
109
|
|
693
|
+
110
|
|
694
|
+
111
|
|
695
|
+
112
|
|
696
|
+
113
|
|
697
|
+
114
|
|
698
|
+
115
|
|
699
|
+
116
|
|
700
|
+
117
|
|
701
|
+
118
|
|
702
|
+
119
|
|
703
|
+
120
|
|
704
|
+
121
|
|
705
|
+
122
|
|
706
|
+
123
|
|
707
|
+
124
|
|
708
|
+
125
|
|
709
|
+
126
|
|
710
|
+
127
|
|
711
|
+
128
|
|
712
|
+
129
|
|
713
|
+
130</pre>
|
|
714
|
+
</td>
|
|
715
|
+
<td>
|
|
716
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 108</span>
|
|
717
|
+
|
|
718
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load_schema'>load_schema</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
|
|
719
|
+
<span class='comment'># Get service path based on class name (e.g., "process_payment" from "Servus::ProcessPayment::Service")
|
|
720
|
+
</span> <span class='id identifier rubyid_service_namespace'>service_namespace</span> <span class='op'>=</span> <span class='id identifier rubyid_parse_service_namespace'>parse_service_namespace</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='rparen'>)</span>
|
|
721
|
+
<span class='id identifier rubyid_schema_path'>schema_path</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../../Servus.html" title="Servus (module)">Servus</a></span></span><span class='period'>.</span><span class='id identifier rubyid_config'><span class='object_link'><a href="../../Servus.html#config-class_method" title="Servus.config (method)">config</a></span></span><span class='period'>.</span><span class='id identifier rubyid_schema_path_for'><span class='object_link'><a href="../Config.html#schema_path_for-instance_method" title="Servus::Config#schema_path_for (method)">schema_path_for</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_service_namespace'>service_namespace</span><span class='comma'>,</span> <span class='id identifier rubyid_type'>type</span><span class='rparen'>)</span>
|
|
722
|
+
|
|
723
|
+
<span class='comment'># Return from cache if available
|
|
724
|
+
</span> <span class='kw'>return</span> <span class='ivar'>@schema_cache</span><span class='lbracket'>[</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='ivar'>@schema_cache</span><span class='period'>.</span><span class='id identifier rubyid_key?'>key?</span><span class='lparen'>(</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rparen'>)</span>
|
|
725
|
+
|
|
726
|
+
<span class='comment'># Check for DSL-defined schema first
|
|
727
|
+
</span> <span class='id identifier rubyid_dsl_schema'>dsl_schema</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='id identifier rubyid_type'>type</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>arguments</span><span class='tstring_end'>'</span></span>
|
|
728
|
+
<span class='id identifier rubyid_service_class'>service_class</span><span class='period'>.</span><span class='id identifier rubyid_arguments_schema'>arguments_schema</span>
|
|
729
|
+
<span class='kw'>else</span>
|
|
730
|
+
<span class='id identifier rubyid_service_class'>service_class</span><span class='period'>.</span><span class='id identifier rubyid_result_schema'>result_schema</span>
|
|
731
|
+
<span class='kw'>end</span>
|
|
732
|
+
|
|
733
|
+
<span class='id identifier rubyid_inline_schema_constant_name'>inline_schema_constant_name</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_service_class'>service_class</span><span class='embexpr_end'>}</span><span class='tstring_content'>::</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_type'>type</span><span class='period'>.</span><span class='id identifier rubyid_upcase'>upcase</span><span class='embexpr_end'>}</span><span class='tstring_content'>_SCHEMA</span><span class='tstring_end'>"</span></span>
|
|
734
|
+
<span class='id identifier rubyid_inline_schema_constant'>inline_schema_constant</span> <span class='op'>=</span> <span class='kw'>if</span> <span class='const'>Object</span><span class='period'>.</span><span class='id identifier rubyid_const_defined?'>const_defined?</span><span class='lparen'>(</span><span class='id identifier rubyid_inline_schema_constant_name'>inline_schema_constant_name</span><span class='rparen'>)</span>
|
|
735
|
+
<span class='const'>Object</span><span class='period'>.</span><span class='id identifier rubyid_const_get'>const_get</span><span class='lparen'>(</span><span class='id identifier rubyid_inline_schema_constant_name'>inline_schema_constant_name</span><span class='rparen'>)</span>
|
|
736
|
+
<span class='kw'>end</span>
|
|
737
|
+
|
|
738
|
+
<span class='ivar'>@schema_cache</span><span class='lbracket'>[</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_fetch_schema_from_sources'>fetch_schema_from_sources</span><span class='lparen'>(</span><span class='id identifier rubyid_dsl_schema'>dsl_schema</span><span class='comma'>,</span> <span class='id identifier rubyid_inline_schema_constant'>inline_schema_constant</span><span class='comma'>,</span> <span class='id identifier rubyid_schema_path'>schema_path</span><span class='rparen'>)</span>
|
|
739
|
+
<span class='ivar'>@schema_cache</span><span class='lbracket'>[</span><span class='id identifier rubyid_schema_path'>schema_path</span><span class='rbracket'>]</span>
|
|
740
|
+
<span class='kw'>end</span></pre>
|
|
741
|
+
</td>
|
|
742
|
+
</tr>
|
|
743
|
+
</table>
|
|
744
|
+
</div>
|
|
745
|
+
|
|
746
|
+
<div class="method_details ">
|
|
747
|
+
<h3 class="signature " id="parse_service_namespace-class_method">
|
|
748
|
+
|
|
749
|
+
.<strong>parse_service_namespace</strong>(service_class) ⇒ <tt>String</tt>
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
</h3><div class="docstring">
|
|
756
|
+
<div class="discussion">
|
|
757
|
+
<p class="note private">
|
|
758
|
+
<strong>This method is part of a private API.</strong>
|
|
759
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
760
|
+
</p>
|
|
761
|
+
<p>Converts service class name to file path namespace.</p>
|
|
762
|
+
|
|
763
|
+
<p>Transforms a class name like "Services::ProcessPayment::Service" into
|
|
764
|
+
"services/process_payment" for locating schema files.</p>
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
</div>
|
|
768
|
+
</div>
|
|
769
|
+
<div class="tags">
|
|
770
|
+
|
|
771
|
+
<div class="examples">
|
|
772
|
+
<h4 class="tag_title">Examples:</h4>
|
|
773
|
+
|
|
774
|
+
|
|
775
|
+
<pre class="example code"><code><span class='id identifier rubyid_parse_service_namespace'>parse_service_namespace</span><span class='lparen'>(</span><span class='const'>Services</span><span class='op'>::</span><span class='const'>ProcessPayment</span><span class='op'>::</span><span class='const'>Service</span><span class='rparen'>)</span>
|
|
776
|
+
<span class='comment'># => "services/process_payment"</span></code></pre>
|
|
777
|
+
|
|
778
|
+
</div>
|
|
779
|
+
<p class="tag_title">Parameters:</p>
|
|
780
|
+
<ul class="param">
|
|
781
|
+
|
|
782
|
+
<li>
|
|
783
|
+
|
|
784
|
+
<span class='name'>service_class</span>
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
—
|
|
792
|
+
<div class='inline'><p>the service class</p>
|
|
793
|
+
</div>
|
|
794
|
+
|
|
795
|
+
</li>
|
|
796
|
+
|
|
797
|
+
</ul>
|
|
798
|
+
|
|
799
|
+
<p class="tag_title">Returns:</p>
|
|
800
|
+
<ul class="return">
|
|
801
|
+
|
|
802
|
+
<li>
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
<span class='type'>(<tt>String</tt>)</span>
|
|
806
|
+
|
|
807
|
+
|
|
808
|
+
|
|
809
|
+
—
|
|
810
|
+
<div class='inline'><p>underscored namespace path</p>
|
|
811
|
+
</div>
|
|
812
|
+
|
|
813
|
+
</li>
|
|
814
|
+
|
|
815
|
+
</ul>
|
|
816
|
+
|
|
817
|
+
</div><table class="source_code">
|
|
818
|
+
<tr>
|
|
819
|
+
<td>
|
|
820
|
+
<pre class="lines">
|
|
821
|
+
|
|
822
|
+
|
|
823
|
+
193
|
|
824
|
+
194
|
|
825
|
+
195
|
|
826
|
+
196
|
|
827
|
+
197</pre>
|
|
828
|
+
</td>
|
|
829
|
+
<td>
|
|
830
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 193</span>
|
|
831
|
+
|
|
832
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_parse_service_namespace'>parse_service_namespace</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='rparen'>)</span>
|
|
833
|
+
<span class='id identifier rubyid_service_class'>service_class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>::</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='lbracket'>[</span><span class='op'>..</span><span class='op'>-</span><span class='int'>2</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_s'>s</span><span class='op'>|</span>
|
|
834
|
+
<span class='id identifier rubyid_s'>s</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>([a-z])([A-Z])</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>\1_\2</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_downcase'>downcase</span>
|
|
835
|
+
<span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>/</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
836
|
+
<span class='kw'>end</span></pre>
|
|
837
|
+
</td>
|
|
838
|
+
</tr>
|
|
839
|
+
</table>
|
|
840
|
+
</div>
|
|
841
|
+
|
|
842
|
+
<div class="method_details ">
|
|
843
|
+
<h3 class="signature " id="validate_arguments!-class_method">
|
|
844
|
+
|
|
845
|
+
.<strong>validate_arguments!</strong>(service_class, args) ⇒ <tt>Boolean</tt>
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
</h3><div class="docstring">
|
|
852
|
+
<div class="discussion">
|
|
853
|
+
<p class="note private">
|
|
854
|
+
<strong>This method is part of a private API.</strong>
|
|
855
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
856
|
+
</p>
|
|
857
|
+
<p>Validates service arguments against the ARGUMENTS_SCHEMA.</p>
|
|
858
|
+
|
|
859
|
+
<p>Checks arguments against either an inline ARGUMENTS_SCHEMA constant or
|
|
860
|
+
a file-based schema at app/schemas/services/namespace/arguments.json.
|
|
861
|
+
Validation is skipped if no schema is defined.</p>
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
</div>
|
|
865
|
+
</div>
|
|
866
|
+
<div class="tags">
|
|
867
|
+
|
|
868
|
+
<div class="examples">
|
|
869
|
+
<h4 class="tag_title">Examples:</h4>
|
|
870
|
+
|
|
871
|
+
|
|
872
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Servus::Support::Validator (class)">Validator</a></span></span><span class='period'>.</span><span class='id identifier rubyid_validate_arguments!'>validate_arguments!</span><span class='lparen'>(</span><span class='const'>MyService</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='label'>user_id:</span> <span class='int'>123</span> <span class='rbrace'>}</span><span class='rparen'>)</span></code></pre>
|
|
873
|
+
|
|
874
|
+
</div>
|
|
875
|
+
<p class="tag_title">Parameters:</p>
|
|
876
|
+
<ul class="param">
|
|
877
|
+
|
|
878
|
+
<li>
|
|
879
|
+
|
|
880
|
+
<span class='name'>service_class</span>
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
|
884
|
+
|
|
885
|
+
|
|
886
|
+
|
|
887
|
+
—
|
|
888
|
+
<div class='inline'><p>the service class being validated</p>
|
|
889
|
+
</div>
|
|
890
|
+
|
|
891
|
+
</li>
|
|
892
|
+
|
|
893
|
+
<li>
|
|
894
|
+
|
|
895
|
+
<span class='name'>args</span>
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
|
899
|
+
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
—
|
|
903
|
+
<div class='inline'><p>keyword arguments passed to the service</p>
|
|
904
|
+
</div>
|
|
905
|
+
|
|
906
|
+
</li>
|
|
907
|
+
|
|
908
|
+
</ul>
|
|
909
|
+
|
|
910
|
+
<p class="tag_title">Returns:</p>
|
|
911
|
+
<ul class="return">
|
|
912
|
+
|
|
913
|
+
<li>
|
|
914
|
+
|
|
915
|
+
|
|
916
|
+
<span class='type'>(<tt>Boolean</tt>)</span>
|
|
917
|
+
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
—
|
|
921
|
+
<div class='inline'><p>true if validation passes</p>
|
|
922
|
+
</div>
|
|
923
|
+
|
|
924
|
+
</li>
|
|
925
|
+
|
|
926
|
+
</ul>
|
|
927
|
+
<p class="tag_title">Raises:</p>
|
|
928
|
+
<ul class="raise">
|
|
929
|
+
|
|
930
|
+
<li>
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
<span class='type'>(<tt><span class='object_link'><a href="Errors/ValidationError.html" title="Servus::Support::Errors::ValidationError (class)">Servus::Support::Errors::ValidationError</a></span></tt>)</span>
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
—
|
|
938
|
+
<div class='inline'><p>if arguments fail validation</p>
|
|
939
|
+
</div>
|
|
940
|
+
|
|
941
|
+
</li>
|
|
942
|
+
|
|
943
|
+
</ul>
|
|
944
|
+
|
|
945
|
+
</div><table class="source_code">
|
|
946
|
+
<tr>
|
|
947
|
+
<td>
|
|
948
|
+
<pre class="lines">
|
|
949
|
+
|
|
950
|
+
|
|
951
|
+
46
|
|
952
|
+
47
|
|
953
|
+
48
|
|
954
|
+
49
|
|
955
|
+
50
|
|
956
|
+
51
|
|
957
|
+
52
|
|
958
|
+
53
|
|
959
|
+
54
|
|
960
|
+
55
|
|
961
|
+
56
|
|
962
|
+
57
|
|
963
|
+
58
|
|
964
|
+
59</pre>
|
|
965
|
+
</td>
|
|
966
|
+
<td>
|
|
967
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 46</span>
|
|
968
|
+
|
|
969
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_arguments!'>validate_arguments!</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='comma'>,</span> <span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span>
|
|
970
|
+
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='id identifier rubyid_load_schema'>load_schema</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>arguments</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
971
|
+
<span class='kw'>return</span> <span class='kw'>true</span> <span class='kw'>unless</span> <span class='id identifier rubyid_schema'>schema</span> <span class='comment'># Skip validation if no schema exists
|
|
972
|
+
</span>
|
|
973
|
+
<span class='id identifier rubyid_serialized_result'>serialized_result</span> <span class='op'>=</span> <span class='id identifier rubyid_args'>args</span><span class='period'>.</span><span class='id identifier rubyid_as_json'>as_json</span>
|
|
974
|
+
<span class='id identifier rubyid_validation_errors'>validation_errors</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='op'>::</span><span class='const'>Validator</span><span class='period'>.</span><span class='id identifier rubyid_fully_validate'>fully_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='comma'>,</span> <span class='id identifier rubyid_serialized_result'>serialized_result</span><span class='rparen'>)</span>
|
|
975
|
+
|
|
976
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_validation_errors'>validation_errors</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
|
|
977
|
+
<span class='id identifier rubyid_error_message'>error_message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid arguments for </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_service_class'>service_class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_validation_errors'>validation_errors</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>, </span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
978
|
+
<span class='id identifier rubyid_raise'>raise</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><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors/ValidationError.html" title="Servus::Support::Errors::ValidationError (class)">ValidationError</a></span></span><span class='comma'>,</span> <span class='id identifier rubyid_error_message'>error_message</span>
|
|
979
|
+
<span class='kw'>end</span>
|
|
980
|
+
|
|
981
|
+
<span class='kw'>true</span>
|
|
982
|
+
<span class='kw'>end</span></pre>
|
|
983
|
+
</td>
|
|
984
|
+
</tr>
|
|
985
|
+
</table>
|
|
986
|
+
</div>
|
|
987
|
+
|
|
988
|
+
<div class="method_details ">
|
|
989
|
+
<h3 class="signature " id="validate_result!-class_method">
|
|
990
|
+
|
|
991
|
+
.<strong>validate_result!</strong>(service_class, result) ⇒ <tt><span class='object_link'><a href="Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
996
|
+
|
|
997
|
+
</h3><div class="docstring">
|
|
998
|
+
<div class="discussion">
|
|
999
|
+
<p class="note private">
|
|
1000
|
+
<strong>This method is part of a private API.</strong>
|
|
1001
|
+
You should avoid using this method if possible, as it may be removed or be changed in the future.
|
|
1002
|
+
</p>
|
|
1003
|
+
<p>Validates service result data against the RESULT_SCHEMA.</p>
|
|
1004
|
+
|
|
1005
|
+
<p>Checks the result.data against either an inline RESULT_SCHEMA constant or
|
|
1006
|
+
a file-based schema at app/schemas/services/namespace/result.json.
|
|
1007
|
+
Only validates successful responses; failures are skipped.</p>
|
|
1008
|
+
|
|
1009
|
+
|
|
1010
|
+
</div>
|
|
1011
|
+
</div>
|
|
1012
|
+
<div class="tags">
|
|
1013
|
+
|
|
1014
|
+
<div class="examples">
|
|
1015
|
+
<h4 class="tag_title">Examples:</h4>
|
|
1016
|
+
|
|
1017
|
+
|
|
1018
|
+
<pre class="example code"><code><span class='const'><span class='object_link'><a href="" title="Servus::Support::Validator (class)">Validator</a></span></span><span class='period'>.</span><span class='id identifier rubyid_validate_result!'>validate_result!</span><span class='lparen'>(</span><span class='const'>MyService</span><span class='comma'>,</span> <span class='id identifier rubyid_response'>response</span><span class='rparen'>)</span></code></pre>
|
|
1019
|
+
|
|
1020
|
+
</div>
|
|
1021
|
+
<p class="tag_title">Parameters:</p>
|
|
1022
|
+
<ul class="param">
|
|
1023
|
+
|
|
1024
|
+
<li>
|
|
1025
|
+
|
|
1026
|
+
<span class='name'>service_class</span>
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
—
|
|
1034
|
+
<div class='inline'><p>the service class being validated</p>
|
|
1035
|
+
</div>
|
|
1036
|
+
|
|
1037
|
+
</li>
|
|
1038
|
+
|
|
1039
|
+
<li>
|
|
1040
|
+
|
|
1041
|
+
<span class='name'>result</span>
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
<span class='type'>(<tt><span class='object_link'><a href="Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>)</span>
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
—
|
|
1049
|
+
<div class='inline'><p>the response object to validate</p>
|
|
1050
|
+
</div>
|
|
1051
|
+
|
|
1052
|
+
</li>
|
|
1053
|
+
|
|
1054
|
+
</ul>
|
|
1055
|
+
|
|
1056
|
+
<p class="tag_title">Returns:</p>
|
|
1057
|
+
<ul class="return">
|
|
1058
|
+
|
|
1059
|
+
<li>
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
<span class='type'>(<tt><span class='object_link'><a href="Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>)</span>
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
|
|
1066
|
+
—
|
|
1067
|
+
<div class='inline'><p>the original result if validation passes</p>
|
|
1068
|
+
</div>
|
|
1069
|
+
|
|
1070
|
+
</li>
|
|
1071
|
+
|
|
1072
|
+
</ul>
|
|
1073
|
+
<p class="tag_title">Raises:</p>
|
|
1074
|
+
<ul class="raise">
|
|
1075
|
+
|
|
1076
|
+
<li>
|
|
1077
|
+
|
|
1078
|
+
|
|
1079
|
+
<span class='type'>(<tt><span class='object_link'><a href="Errors/ValidationError.html" title="Servus::Support::Errors::ValidationError (class)">Servus::Support::Errors::ValidationError</a></span></tt>)</span>
|
|
1080
|
+
|
|
1081
|
+
|
|
1082
|
+
|
|
1083
|
+
—
|
|
1084
|
+
<div class='inline'><p>if result data fails validation</p>
|
|
1085
|
+
</div>
|
|
1086
|
+
|
|
1087
|
+
</li>
|
|
1088
|
+
|
|
1089
|
+
</ul>
|
|
1090
|
+
|
|
1091
|
+
</div><table class="source_code">
|
|
1092
|
+
<tr>
|
|
1093
|
+
<td>
|
|
1094
|
+
<pre class="lines">
|
|
1095
|
+
|
|
1096
|
+
|
|
1097
|
+
76
|
|
1098
|
+
77
|
|
1099
|
+
78
|
|
1100
|
+
79
|
|
1101
|
+
80
|
|
1102
|
+
81
|
|
1103
|
+
82
|
|
1104
|
+
83
|
|
1105
|
+
84
|
|
1106
|
+
85
|
|
1107
|
+
86
|
|
1108
|
+
87
|
|
1109
|
+
88
|
|
1110
|
+
89
|
|
1111
|
+
90
|
|
1112
|
+
91</pre>
|
|
1113
|
+
</td>
|
|
1114
|
+
<td>
|
|
1115
|
+
<pre class="code"><span class="info file"># File 'lib/servus/support/validator.rb', line 76</span>
|
|
1116
|
+
|
|
1117
|
+
<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_validate_result!'>validate_result!</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='comma'>,</span> <span class='id identifier rubyid_result'>result</span><span class='rparen'>)</span>
|
|
1118
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span> <span class='kw'>unless</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
1119
|
+
|
|
1120
|
+
<span class='id identifier rubyid_schema'>schema</span> <span class='op'>=</span> <span class='id identifier rubyid_load_schema'>load_schema</span><span class='lparen'>(</span><span class='id identifier rubyid_service_class'>service_class</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>result</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span>
|
|
1121
|
+
<span class='kw'>return</span> <span class='id identifier rubyid_result'>result</span> <span class='kw'>unless</span> <span class='id identifier rubyid_schema'>schema</span> <span class='comment'># Skip validation if no schema exists
|
|
1122
|
+
</span>
|
|
1123
|
+
<span class='id identifier rubyid_serialized_result'>serialized_result</span> <span class='op'>=</span> <span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='period'>.</span><span class='id identifier rubyid_as_json'>as_json</span>
|
|
1124
|
+
<span class='id identifier rubyid_validation_errors'>validation_errors</span> <span class='op'>=</span> <span class='const'>JSON</span><span class='op'>::</span><span class='const'>Validator</span><span class='period'>.</span><span class='id identifier rubyid_fully_validate'>fully_validate</span><span class='lparen'>(</span><span class='id identifier rubyid_schema'>schema</span><span class='comma'>,</span> <span class='id identifier rubyid_serialized_result'>serialized_result</span><span class='rparen'>)</span>
|
|
1125
|
+
|
|
1126
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_validation_errors'>validation_errors</span><span class='period'>.</span><span class='id identifier rubyid_any?'>any?</span>
|
|
1127
|
+
<span class='id identifier rubyid_error_message'>error_message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Invalid result structure from </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_service_class'>service_class</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_validation_errors'>validation_errors</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>, </span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span>
|
|
1128
|
+
<span class='id identifier rubyid_raise'>raise</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><span class='op'>::</span><span class='const'><span class='object_link'><a href="Errors/ValidationError.html" title="Servus::Support::Errors::ValidationError (class)">ValidationError</a></span></span><span class='comma'>,</span> <span class='id identifier rubyid_error_message'>error_message</span>
|
|
1129
|
+
<span class='kw'>end</span>
|
|
1130
|
+
|
|
1131
|
+
<span class='id identifier rubyid_result'>result</span>
|
|
1132
|
+
<span class='kw'>end</span></pre>
|
|
1133
|
+
</td>
|
|
1134
|
+
</tr>
|
|
1135
|
+
</table>
|
|
1136
|
+
</div>
|
|
1137
|
+
|
|
1138
|
+
</div>
|
|
1139
|
+
|
|
1140
|
+
</div>
|
|
1141
|
+
|
|
1142
|
+
<div id="footer">
|
|
1143
|
+
Generated on Fri Nov 21 00:33:24 2025 by
|
|
1144
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
1145
|
+
0.9.37 (ruby-3.4.4).
|
|
1146
|
+
</div>
|
|
1147
|
+
|
|
1148
|
+
</div>
|
|
1149
|
+
</body>
|
|
1150
|
+
</html>
|