servus 0.1.3 → 0.1.5
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/.claude/commands/check-docs.md +1 -0
- data/.claude/commands/consistency-check.md +1 -0
- data/.claude/commands/fine-tooth-comb.md +1 -0
- data/.claude/commands/red-green-refactor.md +5 -0
- data/.claude/settings.json +15 -0
- data/.rubocop.yml +18 -2
- data/.yardopts +6 -0
- data/CHANGELOG.md +47 -0
- data/CLAUDE.md +10 -0
- data/IDEAS.md +5 -0
- data/READme.md +300 -47
- data/Rakefile +33 -0
- data/builds/servus-0.1.3.gem +0 -0
- data/builds/servus-0.1.4.gem +0 -0
- data/builds/servus-0.1.5.gem +0 -0
- data/docs/core/1_overview.md +77 -0
- data/docs/core/2_architecture.md +120 -0
- data/docs/core/3_service_objects.md +121 -0
- data/docs/current_focus.md +569 -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/features/5_event_bus.md +244 -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 +104 -0
- data/docs/integration/2_testing.md +287 -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/event_handler/event_handler_generator.rb +59 -0
- data/lib/generators/servus/event_handler/templates/handler.rb.erb +86 -0
- data/lib/generators/servus/event_handler/templates/handler_spec.rb.erb +48 -0
- data/lib/generators/servus/service/service_generator.rb +68 -1
- data/lib/generators/servus/service/templates/arguments.json.erb +19 -10
- data/lib/generators/servus/service/templates/result.json.erb +8 -2
- data/lib/generators/servus/service/templates/service.rb.erb +102 -5
- data/lib/generators/servus/service/templates/service_spec.rb.erb +67 -6
- data/lib/servus/base.rb +275 -58
- data/lib/servus/config.rb +83 -17
- data/lib/servus/event_handler.rb +275 -0
- data/lib/servus/events/bus.rb +137 -0
- data/lib/servus/events/emitter.rb +162 -0
- data/lib/servus/events/errors.rb +10 -0
- 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 +30 -9
- data/lib/servus/helpers/controller_helpers.rb +73 -37
- data/lib/servus/railtie.rb +16 -0
- 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 +147 -19
- data/lib/servus/testing/example_builders.rb +133 -0
- data/lib/servus/testing/example_extractor.rb +309 -0
- data/lib/servus/testing/matchers.rb +88 -0
- data/lib/servus/testing.rb +19 -0
- data/lib/servus/version.rb +1 -1
- data/lib/servus.rb +6 -0
- metadata +135 -19
|
@@ -0,0 +1,457 @@
|
|
|
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::Helpers::ControllerHelpers
|
|
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::Helpers::ControllerHelpers";
|
|
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> »
|
|
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="../Helpers.html" title="Servus::Helpers (module)">Helpers</a></span></span>
|
|
41
|
+
»
|
|
42
|
+
<span class="title">ControllerHelpers</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::Helpers::ControllerHelpers
|
|
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/helpers/controller_helpers.rb</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<h2>Overview</h2><div class="docstring">
|
|
87
|
+
<div class="discussion">
|
|
88
|
+
<p>Rails controller helper methods for service integration.</p>
|
|
89
|
+
|
|
90
|
+
<p>Provides convenient methods for calling services from controllers and
|
|
91
|
+
handling their responses. Automatically included in ActionController::Base
|
|
92
|
+
when Servus is loaded in a Rails application.</p>
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
<div class="tags">
|
|
98
|
+
|
|
99
|
+
<div class="examples">
|
|
100
|
+
<h4 class="tag_title">Examples:</h4>
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
<h5 class="example_title"><div class='inline'><p>Including in a controller</p>
|
|
104
|
+
</div></h5>
|
|
105
|
+
|
|
106
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>ApplicationController</span> <span class='op'><</span> <span class='const'>ActionController</span><span class='op'>::</span><span class='const'>Base</span>
|
|
107
|
+
<span class='id identifier rubyid_include'>include</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="../Helpers.html" title="Servus::Helpers (module)">Helpers</a></span></span><span class='op'>::</span><span class='const'>ControllerHelpers</span>
|
|
108
|
+
<span class='kw'>end</span></code></pre>
|
|
109
|
+
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
<p class="tag_title">See Also:</p>
|
|
114
|
+
<ul class="see">
|
|
115
|
+
|
|
116
|
+
<li><span class='object_link'><a href="#run_service-instance_method" title="Servus::Helpers::ControllerHelpers#run_service (method)">#run_service</a></span></li>
|
|
117
|
+
|
|
118
|
+
<li><span class='object_link'><a href="#render_service_object_error-instance_method" title="Servus::Helpers::ControllerHelpers#render_service_object_error (method)">#render_service_object_error</a></span></li>
|
|
119
|
+
|
|
120
|
+
</ul>
|
|
121
|
+
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
<h2>
|
|
131
|
+
Instance Method Summary
|
|
132
|
+
<small><a href="#" class="summary_toggle">collapse</a></small>
|
|
133
|
+
</h2>
|
|
134
|
+
|
|
135
|
+
<ul class="summary">
|
|
136
|
+
|
|
137
|
+
<li class="public ">
|
|
138
|
+
<span class="summary_signature">
|
|
139
|
+
|
|
140
|
+
<a href="#render_service_object_error-instance_method" title="#render_service_object_error (instance method)">#<strong>render_service_object_error</strong>(api_error) ⇒ void </a>
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
</span>
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
<span class="summary_desc"><div class='inline'><p>Renders a service error as a JSON response.</p>
|
|
155
|
+
</div></span>
|
|
156
|
+
|
|
157
|
+
</li>
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
<li class="public ">
|
|
161
|
+
<span class="summary_signature">
|
|
162
|
+
|
|
163
|
+
<a href="#run_service-instance_method" title="#run_service (instance method)">#<strong>run_service</strong>(klass, params) ⇒ Servus::Support::Response<sup>?</sup> </a>
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
</span>
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
<span class="summary_desc"><div class='inline'><p>Executes a service and handles success/failure automatically.</p>
|
|
178
|
+
</div></span>
|
|
179
|
+
|
|
180
|
+
</li>
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
</ul>
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
<div id="instance_method_details" class="method_details_list">
|
|
189
|
+
<h2>Instance Method Details</h2>
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
<div class="method_details first">
|
|
193
|
+
<h3 class="signature first" id="render_service_object_error-instance_method">
|
|
194
|
+
|
|
195
|
+
#<strong>render_service_object_error</strong>(api_error) ⇒ <tt>void</tt>
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
</h3><div class="docstring">
|
|
202
|
+
<div class="discussion">
|
|
203
|
+
<p class="note returns_void">This method returns an undefined value.</p><p>Renders a service error as a JSON response.</p>
|
|
204
|
+
|
|
205
|
+
<p>This method is called automatically by <span class='object_link'><a href="#run_service-instance_method" title="Servus::Helpers::ControllerHelpers#run_service (method)">#run_service</a></span> when a service fails,
|
|
206
|
+
but can also be called manually for custom error handling. It renders the
|
|
207
|
+
error's api_error hash with the appropriate HTTP status code.</p>
|
|
208
|
+
|
|
209
|
+
<p>Override this method in your controller to customize error response format.</p>
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
</div>
|
|
213
|
+
</div>
|
|
214
|
+
<div class="tags">
|
|
215
|
+
|
|
216
|
+
<div class="examples">
|
|
217
|
+
<h4 class="tag_title">Examples:</h4>
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
<h5 class="example_title"><div class='inline'><p>Default behavior</p>
|
|
221
|
+
</div></h5>
|
|
222
|
+
|
|
223
|
+
<pre class="example code"><code><span class='comment'># Renders: { code: :not_found, message: "User not found" }
|
|
224
|
+
</span><span class='comment'># With status: 404
|
|
225
|
+
</span><span class='id identifier rubyid_render_service_object_error'>render_service_object_error</span><span class='lparen'>(</span><span class='id identifier rubyid_result'>result</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_api_error'>api_error</span><span class='rparen'>)</span></code></pre>
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
<h5 class="example_title"><div class='inline'><p>Custom error rendering</p>
|
|
229
|
+
</div></h5>
|
|
230
|
+
|
|
231
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>ApplicationController</span> <span class='op'><</span> <span class='const'>ActionController</span><span class='op'>::</span><span class='const'>Base</span>
|
|
232
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_render_service_object_error'>render_service_object_error</span><span class='lparen'>(</span><span class='id identifier rubyid_api_error'>api_error</span><span class='rparen'>)</span>
|
|
233
|
+
<span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='lbrace'>{</span>
|
|
234
|
+
<span class='label'>error:</span> <span class='lbrace'>{</span>
|
|
235
|
+
<span class='label'>type:</span> <span class='id identifier rubyid_api_error'>api_error</span><span class='lbracket'>[</span><span class='symbol'>:code</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
|
236
|
+
<span class='label'>details:</span> <span class='id identifier rubyid_api_error'>api_error</span><span class='lbracket'>[</span><span class='symbol'>:message</span><span class='rbracket'>]</span><span class='comma'>,</span>
|
|
237
|
+
<span class='label'>timestamp:</span> <span class='const'>Time</span><span class='period'>.</span><span class='id identifier rubyid_current'>current</span>
|
|
238
|
+
<span class='rbrace'>}</span>
|
|
239
|
+
<span class='rbrace'>}</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='id identifier rubyid_api_error'>api_error</span><span class='lbracket'>[</span><span class='symbol'>:code</span><span class='rbracket'>]</span>
|
|
240
|
+
<span class='kw'>end</span>
|
|
241
|
+
<span class='kw'>end</span></code></pre>
|
|
242
|
+
|
|
243
|
+
</div>
|
|
244
|
+
<p class="tag_title">Parameters:</p>
|
|
245
|
+
<ul class="param">
|
|
246
|
+
|
|
247
|
+
<li>
|
|
248
|
+
|
|
249
|
+
<span class='name'>api_error</span>
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
—
|
|
257
|
+
<div class='inline'><p>error hash with :code and :message keys from <span class='object_link'><a href="../Support/Errors/ServiceError.html#api_error-instance_method" title="Servus::Support::Errors::ServiceError#api_error (method)">Support::Errors::ServiceError#api_error</a></span></p>
|
|
258
|
+
</div>
|
|
259
|
+
|
|
260
|
+
</li>
|
|
261
|
+
|
|
262
|
+
</ul>
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
<p class="tag_title">See Also:</p>
|
|
266
|
+
<ul class="see">
|
|
267
|
+
|
|
268
|
+
<li><span class='object_link'><a href="../Support/Errors/ServiceError.html#api_error-instance_method" title="Servus::Support::Errors::ServiceError#api_error (method)">Support::Errors::ServiceError#api_error</a></span></li>
|
|
269
|
+
|
|
270
|
+
<li><span class='object_link'><a href="#run_service-instance_method" title="Servus::Helpers::ControllerHelpers#run_service (method)">#run_service</a></span></li>
|
|
271
|
+
|
|
272
|
+
</ul>
|
|
273
|
+
|
|
274
|
+
</div><table class="source_code">
|
|
275
|
+
<tr>
|
|
276
|
+
<td>
|
|
277
|
+
<pre class="lines">
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
97
|
|
281
|
+
98
|
|
282
|
+
99</pre>
|
|
283
|
+
</td>
|
|
284
|
+
<td>
|
|
285
|
+
<pre class="code"><span class="info file"># File 'lib/servus/helpers/controller_helpers.rb', line 97</span>
|
|
286
|
+
|
|
287
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_render_service_object_error'>render_service_object_error</span><span class='lparen'>(</span><span class='id identifier rubyid_api_error'>api_error</span><span class='rparen'>)</span>
|
|
288
|
+
<span class='id identifier rubyid_render'>render</span> <span class='label'>json:</span> <span class='id identifier rubyid_api_error'>api_error</span><span class='comma'>,</span> <span class='label'>status:</span> <span class='id identifier rubyid_api_error'>api_error</span><span class='lbracket'>[</span><span class='symbol'>:code</span><span class='rbracket'>]</span>
|
|
289
|
+
<span class='kw'>end</span></pre>
|
|
290
|
+
</td>
|
|
291
|
+
</tr>
|
|
292
|
+
</table>
|
|
293
|
+
</div>
|
|
294
|
+
|
|
295
|
+
<div class="method_details ">
|
|
296
|
+
<h3 class="signature " id="run_service-instance_method">
|
|
297
|
+
|
|
298
|
+
#<strong>run_service</strong>(klass, params) ⇒ <tt><span class='object_link'><a href="../Support/Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt><sup>?</sup>
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
</h3><div class="docstring">
|
|
305
|
+
<div class="discussion">
|
|
306
|
+
<p>Executes a service and handles success/failure automatically.</p>
|
|
307
|
+
|
|
308
|
+
<p>This method runs the service with the provided parameters. On success,
|
|
309
|
+
it stores the result in @result for use in views. On failure, it
|
|
310
|
+
automatically calls <span class='object_link'><a href="#render_service_object_error-instance_method" title="Servus::Helpers::ControllerHelpers#render_service_object_error (method)">#render_service_object_error</a></span> with the error details.</p>
|
|
311
|
+
|
|
312
|
+
<p>The result is always stored in the @result instance variable, making it
|
|
313
|
+
available in views for rendering successful responses.</p>
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
</div>
|
|
317
|
+
</div>
|
|
318
|
+
<div class="tags">
|
|
319
|
+
|
|
320
|
+
<div class="examples">
|
|
321
|
+
<h4 class="tag_title">Examples:</h4>
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
<h5 class="example_title"><div class='inline'><p>Basic usage</p>
|
|
325
|
+
</div></h5>
|
|
326
|
+
|
|
327
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>UsersController</span> <span class='op'><</span> <span class='const'>ApplicationController</span>
|
|
328
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span>
|
|
329
|
+
<span class='id identifier rubyid_run_service'>run_service</span> <span class='const'>Services</span><span class='op'>::</span><span class='const'>CreateUser</span><span class='op'>::</span><span class='const'>Service</span><span class='comma'>,</span> <span class='id identifier rubyid_user_params'>user_params</span>
|
|
330
|
+
<span class='comment'># If successful, @result is available for rendering
|
|
331
|
+
</span> <span class='comment'># If failed, error response is automatically rendered
|
|
332
|
+
</span> <span class='kw'>end</span>
|
|
333
|
+
<span class='kw'>end</span></code></pre>
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
<h5 class="example_title"><div class='inline'><p>Using @result in views</p>
|
|
337
|
+
</div></h5>
|
|
338
|
+
|
|
339
|
+
<pre class="example code"><code><span class='comment'># In your Jbuilder view (create.json.jbuilder)
|
|
340
|
+
</span><span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_user'>user</span> <span class='kw'>do</span>
|
|
341
|
+
<span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span> <span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:user_id</span><span class='rbracket'>]</span>
|
|
342
|
+
<span class='id identifier rubyid_json'>json</span><span class='period'>.</span><span class='id identifier rubyid_email'>email</span> <span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:email</span><span class='rbracket'>]</span>
|
|
343
|
+
<span class='kw'>end</span></code></pre>
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
<h5 class="example_title"><div class='inline'><p>Manual success handling</p>
|
|
347
|
+
</div></h5>
|
|
348
|
+
|
|
349
|
+
<pre class="example code"><code><span class='kw'>class</span> <span class='const'>UsersController</span> <span class='op'><</span> <span class='const'>ApplicationController</span>
|
|
350
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_create'>create</span>
|
|
351
|
+
<span class='id identifier rubyid_run_service'>run_service</span> <span class='const'>Services</span><span class='op'>::</span><span class='const'>CreateUser</span><span class='op'>::</span><span class='const'>Service</span><span class='comma'>,</span> <span class='id identifier rubyid_user_params'>user_params</span>
|
|
352
|
+
<span class='kw'>return</span> <span class='kw'>unless</span> <span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
353
|
+
|
|
354
|
+
<span class='comment'># Custom success handling
|
|
355
|
+
</span> <span class='id identifier rubyid_redirect_to'>redirect_to</span> <span class='id identifier rubyid_user_path'>user_path</span><span class='lparen'>(</span><span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_data'>data</span><span class='lbracket'>[</span><span class='symbol'>:user_id</span><span class='rbracket'>]</span><span class='rparen'>)</span>
|
|
356
|
+
<span class='kw'>end</span>
|
|
357
|
+
<span class='kw'>end</span></code></pre>
|
|
358
|
+
|
|
359
|
+
</div>
|
|
360
|
+
<p class="tag_title">Parameters:</p>
|
|
361
|
+
<ul class="param">
|
|
362
|
+
|
|
363
|
+
<li>
|
|
364
|
+
|
|
365
|
+
<span class='name'>klass</span>
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
<span class='type'>(<tt>Class</tt>)</span>
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
—
|
|
373
|
+
<div class='inline'><p>service class to execute (must inherit from <span class='object_link'><a href="../Base.html" title="Servus::Base (class)">Base</a></span>)</p>
|
|
374
|
+
</div>
|
|
375
|
+
|
|
376
|
+
</li>
|
|
377
|
+
|
|
378
|
+
<li>
|
|
379
|
+
|
|
380
|
+
<span class='name'>params</span>
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
<span class='type'>(<tt>Hash</tt>)</span>
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
—
|
|
388
|
+
<div class='inline'><p>keyword arguments to pass to the service</p>
|
|
389
|
+
</div>
|
|
390
|
+
|
|
391
|
+
</li>
|
|
392
|
+
|
|
393
|
+
</ul>
|
|
394
|
+
|
|
395
|
+
<p class="tag_title">Returns:</p>
|
|
396
|
+
<ul class="return">
|
|
397
|
+
|
|
398
|
+
<li>
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
<span class='type'>(<tt><span class='object_link'><a href="../Support/Response.html" title="Servus::Support::Response (class)">Servus::Support::Response</a></span></tt>, <tt>nil</tt>)</span>
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
—
|
|
406
|
+
<div class='inline'><p>the service result, or nil if error rendered</p>
|
|
407
|
+
</div>
|
|
408
|
+
|
|
409
|
+
</li>
|
|
410
|
+
|
|
411
|
+
</ul>
|
|
412
|
+
|
|
413
|
+
<p class="tag_title">See Also:</p>
|
|
414
|
+
<ul class="see">
|
|
415
|
+
|
|
416
|
+
<li><span class='object_link'><a href="#render_service_object_error-instance_method" title="Servus::Helpers::ControllerHelpers#render_service_object_error (method)">#render_service_object_error</a></span></li>
|
|
417
|
+
|
|
418
|
+
<li><span class='object_link'><a href="../Base.html#call-class_method" title="Servus::Base.call (method)">Base.call</a></span></li>
|
|
419
|
+
|
|
420
|
+
</ul>
|
|
421
|
+
|
|
422
|
+
</div><table class="source_code">
|
|
423
|
+
<tr>
|
|
424
|
+
<td>
|
|
425
|
+
<pre class="lines">
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
61
|
|
429
|
+
62
|
|
430
|
+
63
|
|
431
|
+
64</pre>
|
|
432
|
+
</td>
|
|
433
|
+
<td>
|
|
434
|
+
<pre class="code"><span class="info file"># File 'lib/servus/helpers/controller_helpers.rb', line 61</span>
|
|
435
|
+
|
|
436
|
+
<span class='kw'>def</span> <span class='id identifier rubyid_run_service'>run_service</span><span class='lparen'>(</span><span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span> <span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
|
|
437
|
+
<span class='ivar'>@result</span> <span class='op'>=</span> <span class='id identifier rubyid_klass'>klass</span><span class='period'>.</span><span class='id identifier rubyid_call'>call</span><span class='lparen'>(</span><span class='op'>**</span><span class='id identifier rubyid_params'>params</span><span class='rparen'>)</span>
|
|
438
|
+
<span class='id identifier rubyid_render_service_object_error'>render_service_object_error</span><span class='lparen'>(</span><span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span><span class='period'>.</span><span class='id identifier rubyid_api_error'>api_error</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='ivar'>@result</span><span class='period'>.</span><span class='id identifier rubyid_success?'>success?</span>
|
|
439
|
+
<span class='kw'>end</span></pre>
|
|
440
|
+
</td>
|
|
441
|
+
</tr>
|
|
442
|
+
</table>
|
|
443
|
+
</div>
|
|
444
|
+
|
|
445
|
+
</div>
|
|
446
|
+
|
|
447
|
+
</div>
|
|
448
|
+
|
|
449
|
+
<div id="footer">
|
|
450
|
+
Generated on Fri Nov 21 00:33:23 2025 by
|
|
451
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
452
|
+
0.9.37 (ruby-3.4.4).
|
|
453
|
+
</div>
|
|
454
|
+
|
|
455
|
+
</div>
|
|
456
|
+
</body>
|
|
457
|
+
</html>
|
|
@@ -0,0 +1,115 @@
|
|
|
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::Helpers
|
|
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::Helpers";
|
|
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 (H)</a> »
|
|
40
|
+
<span class='title'><span class='object_link'><a href="../Servus.html" title="Servus (module)">Servus</a></span></span>
|
|
41
|
+
»
|
|
42
|
+
<span class="title">Helpers</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::Helpers
|
|
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/helpers/controller_helpers.rb</dd>
|
|
82
|
+
</dl>
|
|
83
|
+
|
|
84
|
+
</div>
|
|
85
|
+
|
|
86
|
+
<h2>Defined Under Namespace</h2>
|
|
87
|
+
<p class="children">
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Helpers/ControllerHelpers.html" title="Servus::Helpers::ControllerHelpers (module)">ControllerHelpers</a></span>
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
</p>
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
</div>
|
|
106
|
+
|
|
107
|
+
<div id="footer">
|
|
108
|
+
Generated on Fri Nov 21 00:33:23 2025 by
|
|
109
|
+
<a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
110
|
+
0.9.37 (ruby-3.4.4).
|
|
111
|
+
</div>
|
|
112
|
+
|
|
113
|
+
</div>
|
|
114
|
+
</body>
|
|
115
|
+
</html>
|