decouplio 1.0.0alpha
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 +7 -0
- data/.circleci/config.yml +53 -0
- data/.dockerignore +12 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +106 -0
- data/.rubocop_todo.yml +147 -0
- data/.ruby-version +1 -0
- data/.vscode/settings.json +3 -0
- data/Dockerfile +12 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/benchmarks/.ruby-version +1 -0
- data/benchmarks/Dockerfile +12 -0
- data/benchmarks/Gemfile +11 -0
- data/benchmarks/benchmarks.rb +527 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/decouplio.gemspec +40 -0
- data/docker-compose.yml +18 -0
- data/docs/_config.yml +1 -0
- data/docs/benchmarks.md +1 -0
- data/docs/context.md +74 -0
- data/docs/context.rb +62 -0
- data/docs/doby.md +80 -0
- data/docs/doby.rb +38 -0
- data/docs/error_store.md +347 -0
- data/docs/error_store.rb +202 -0
- data/docs/fail.md +1016 -0
- data/docs/fail.rb +762 -0
- data/docs/index.md +25 -0
- data/docs/inner_action.md +63 -0
- data/docs/inner_action.rb +43 -0
- data/docs/logic_block.md +25 -0
- data/docs/octo.md +269 -0
- data/docs/octo.rb +164 -0
- data/docs/pass.md +309 -0
- data/docs/pass.rb +213 -0
- data/docs/quick_start.md +71 -0
- data/docs/quick_start.rb +38 -0
- data/docs/resq.md +263 -0
- data/docs/resq.rb +176 -0
- data/docs/step.md +737 -0
- data/docs/step.rb +526 -0
- data/docs/step_as_a_service.md +109 -0
- data/docs/step_as_a_service.rb +77 -0
- data/docs/wrap.md +232 -0
- data/docs/wrap.rb +137 -0
- data/lib/decouplio/action.rb +111 -0
- data/lib/decouplio/composer.rb +599 -0
- data/lib/decouplio/const/colors.rb +25 -0
- data/lib/decouplio/const/reserved_methods.rb +18 -0
- data/lib/decouplio/const/results.rb +13 -0
- data/lib/decouplio/const/types.rb +173 -0
- data/lib/decouplio/const/validations/action_option_class.rb +17 -0
- data/lib/decouplio/const/validations/common.rb +14 -0
- data/lib/decouplio/const/validations/fail.rb +34 -0
- data/lib/decouplio/const/validations/logic.rb +15 -0
- data/lib/decouplio/const/validations/octo.rb +44 -0
- data/lib/decouplio/const/validations/palp.rb +20 -0
- data/lib/decouplio/const/validations/pass.rb +32 -0
- data/lib/decouplio/const/validations/resq.rb +67 -0
- data/lib/decouplio/const/validations/step.rb +35 -0
- data/lib/decouplio/const/validations/wrap.rb +41 -0
- data/lib/decouplio/default_error_handler.rb +24 -0
- data/lib/decouplio/errors/action_class_error.rb +26 -0
- data/lib/decouplio/errors/base_error.rb +30 -0
- data/lib/decouplio/errors/error_store_error.rb +17 -0
- data/lib/decouplio/errors/extra_key_for_fail_error.rb +26 -0
- data/lib/decouplio/errors/extra_key_for_octo_error.rb +26 -0
- data/lib/decouplio/errors/extra_key_for_pass_error.rb +26 -0
- data/lib/decouplio/errors/extra_key_for_resq_error.rb +29 -0
- data/lib/decouplio/errors/extra_key_for_step_error.rb +23 -0
- data/lib/decouplio/errors/extra_key_for_wrap_error.rb +23 -0
- data/lib/decouplio/errors/fail_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/fail_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/fail_is_first_step_error.rb +18 -0
- data/lib/decouplio/errors/invalid_error_class_error.rb +29 -0
- data/lib/decouplio/errors/invalid_wrap_name_error.rb +23 -0
- data/lib/decouplio/errors/logic_is_not_defined_error.rb +23 -0
- data/lib/decouplio/errors/logic_redefinition_error.rb +23 -0
- data/lib/decouplio/errors/octo_block_is_not_defined_error.rb +18 -0
- data/lib/decouplio/errors/octo_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/options_validation_error.rb +7 -0
- data/lib/decouplio/errors/palp_block_is_not_defined_error.rb +18 -0
- data/lib/decouplio/errors/palp_is_not_defined_error.rb +26 -0
- data/lib/decouplio/errors/palp_validation_error.rb +21 -0
- data/lib/decouplio/errors/pass_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/pass_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/required_options_is_missing_for_octo_error.rb +25 -0
- data/lib/decouplio/errors/resq_definition_error.rb +21 -0
- data/lib/decouplio/errors/resq_error_class_error.rb +29 -0
- data/lib/decouplio/errors/resq_handler_method_error.rb +26 -0
- data/lib/decouplio/errors/step_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/step_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/step_is_not_defined_for_fail_error.rb +26 -0
- data/lib/decouplio/errors/step_is_not_defined_for_step_error.rb +27 -0
- data/lib/decouplio/errors/step_is_not_defined_for_wrap_error.rb +26 -0
- data/lib/decouplio/errors/step_name_error.rb +20 -0
- data/lib/decouplio/errors/wrap_block_is_not_defined_error.rb +18 -0
- data/lib/decouplio/errors/wrap_controversial_keys_error.rb +26 -0
- data/lib/decouplio/errors/wrap_finish_him_error.rb +26 -0
- data/lib/decouplio/errors/wrap_klass_method_error.rb +23 -0
- data/lib/decouplio/flow.rb +17 -0
- data/lib/decouplio/logic_dsl.rb +96 -0
- data/lib/decouplio/octo_hash_case.rb +31 -0
- data/lib/decouplio/octo_options_validator.rb +89 -0
- data/lib/decouplio/options_validator.rb +566 -0
- data/lib/decouplio/processor.rb +20 -0
- data/lib/decouplio/steps/base_resq.rb +31 -0
- data/lib/decouplio/steps/base_step.rb +16 -0
- data/lib/decouplio/steps/doby.rb +32 -0
- data/lib/decouplio/steps/fail.rb +50 -0
- data/lib/decouplio/steps/if_condition_fail.rb +28 -0
- data/lib/decouplio/steps/if_condition_pass.rb +26 -0
- data/lib/decouplio/steps/inner_action_fail.rb +55 -0
- data/lib/decouplio/steps/inner_action_pass.rb +38 -0
- data/lib/decouplio/steps/inner_action_step.rb +51 -0
- data/lib/decouplio/steps/octo.rb +22 -0
- data/lib/decouplio/steps/pass.rb +35 -0
- data/lib/decouplio/steps/resq_fail.rb +10 -0
- data/lib/decouplio/steps/resq_pass.rb +10 -0
- data/lib/decouplio/steps/service_fail.rb +51 -0
- data/lib/decouplio/steps/service_pass.rb +36 -0
- data/lib/decouplio/steps/service_step.rb +47 -0
- data/lib/decouplio/steps/step.rb +43 -0
- data/lib/decouplio/steps/unless_condition_fail.rb +28 -0
- data/lib/decouplio/steps/unless_condition_pass.rb +26 -0
- data/lib/decouplio/steps/wrap.rb +62 -0
- data/lib/decouplio/validators/condition.rb +49 -0
- data/lib/decouplio/version.rb +5 -0
- data/lib/decouplio.rb +7 -0
- metadata +266 -0
@@ -0,0 +1,527 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_interaction'
|
4
|
+
require 'interactor'
|
5
|
+
require 'mutations'
|
6
|
+
require 'trailblazer'
|
7
|
+
require_relative '../lib/decouplio'
|
8
|
+
require 'pry'
|
9
|
+
require 'benchmark'
|
10
|
+
require 'ruby-prof'
|
11
|
+
|
12
|
+
class MutationTest < Mutations::Command
|
13
|
+
required do
|
14
|
+
string :param1
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute
|
18
|
+
@param1 = 'param1'
|
19
|
+
@context = {}
|
20
|
+
step_one
|
21
|
+
step_two
|
22
|
+
step_three
|
23
|
+
step_four
|
24
|
+
step_five
|
25
|
+
step_six
|
26
|
+
step_seven
|
27
|
+
step_eight
|
28
|
+
step_nine
|
29
|
+
|
30
|
+
@context
|
31
|
+
end
|
32
|
+
|
33
|
+
def step_one
|
34
|
+
@context[:step_one] = @param1
|
35
|
+
end
|
36
|
+
|
37
|
+
def step_two
|
38
|
+
@context[:step_two] = @context[:step_one]
|
39
|
+
end
|
40
|
+
|
41
|
+
def step_three
|
42
|
+
@context[:step_three] = @context[:step_two]
|
43
|
+
end
|
44
|
+
|
45
|
+
def step_four
|
46
|
+
@context[:step_four] = @context[:step_three]
|
47
|
+
end
|
48
|
+
|
49
|
+
def step_five
|
50
|
+
@context[:step_five] = @context[:step_four]
|
51
|
+
end
|
52
|
+
|
53
|
+
def step_six
|
54
|
+
@context[:step_six] = @context[:step_five]
|
55
|
+
end
|
56
|
+
|
57
|
+
def step_seven
|
58
|
+
@context[:step_seven] = @context[:step_six]
|
59
|
+
end
|
60
|
+
|
61
|
+
def step_eight
|
62
|
+
@context[:step_eight] = @context[:step_seven]
|
63
|
+
end
|
64
|
+
|
65
|
+
def step_nine
|
66
|
+
@context[:step_nine] = @context[:step_eight]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class ActiveInteractionTest < ActiveInteraction::Base
|
71
|
+
string :param1
|
72
|
+
|
73
|
+
def execute
|
74
|
+
@context = {}
|
75
|
+
step_one
|
76
|
+
step_two
|
77
|
+
step_three
|
78
|
+
step_four
|
79
|
+
step_five
|
80
|
+
step_six
|
81
|
+
step_seven
|
82
|
+
step_eight
|
83
|
+
step_nine
|
84
|
+
|
85
|
+
@context
|
86
|
+
end
|
87
|
+
|
88
|
+
def step_one
|
89
|
+
@context[:step_one] = param1
|
90
|
+
end
|
91
|
+
|
92
|
+
def step_two
|
93
|
+
@context[:step_two] = @context[:step_one]
|
94
|
+
end
|
95
|
+
|
96
|
+
def step_three
|
97
|
+
@context[:step_three] = @context[:step_two]
|
98
|
+
end
|
99
|
+
|
100
|
+
def step_four
|
101
|
+
@context[:step_four] = @context[:step_three]
|
102
|
+
end
|
103
|
+
|
104
|
+
def step_five
|
105
|
+
@context[:step_five] = @context[:step_four]
|
106
|
+
end
|
107
|
+
|
108
|
+
def step_six
|
109
|
+
@context[:step_six] = @context[:step_five]
|
110
|
+
end
|
111
|
+
|
112
|
+
def step_seven
|
113
|
+
@context[:step_seven] = @context[:step_six]
|
114
|
+
end
|
115
|
+
|
116
|
+
def step_eight
|
117
|
+
@context[:step_eight] = @context[:step_seven]
|
118
|
+
end
|
119
|
+
|
120
|
+
def step_nine
|
121
|
+
@context[:step_nine] = @context[:step_eight]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class DecouplioTestSeveralSteps < Decouplio::Action
|
126
|
+
logic do
|
127
|
+
step :step_one
|
128
|
+
step :step_two
|
129
|
+
step :step_three
|
130
|
+
step :step_four
|
131
|
+
step :step_five
|
132
|
+
step :step_six
|
133
|
+
step :step_seven
|
134
|
+
step :step_eight
|
135
|
+
step :step_nine
|
136
|
+
end
|
137
|
+
|
138
|
+
def step_one(param1:, **)
|
139
|
+
ctx[:step_one] = param1
|
140
|
+
end
|
141
|
+
|
142
|
+
def step_two(step_one:, **)
|
143
|
+
ctx[:step_two] = step_one
|
144
|
+
end
|
145
|
+
|
146
|
+
def step_three(step_two:, **)
|
147
|
+
ctx[:step_three] = step_two
|
148
|
+
end
|
149
|
+
|
150
|
+
def step_four(step_three:, **)
|
151
|
+
ctx[:step_four] = step_three
|
152
|
+
end
|
153
|
+
|
154
|
+
def step_five(step_four:, **)
|
155
|
+
ctx[:step_five] = step_four
|
156
|
+
end
|
157
|
+
|
158
|
+
def step_six(step_five:, **)
|
159
|
+
ctx[:step_six] = step_five
|
160
|
+
end
|
161
|
+
|
162
|
+
def step_seven(step_six:, **)
|
163
|
+
ctx[:step_seven] = step_six
|
164
|
+
end
|
165
|
+
|
166
|
+
def step_eight(step_seven:, **)
|
167
|
+
ctx[:step_eight] = step_seven
|
168
|
+
end
|
169
|
+
|
170
|
+
def step_nine(step_eight:, **)
|
171
|
+
ctx[:step_nine] = step_eight
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
class DecouplioTestOneStep < Decouplio::Action
|
176
|
+
logic do
|
177
|
+
step :step_one
|
178
|
+
end
|
179
|
+
|
180
|
+
def step_one(param1:, **)
|
181
|
+
ctx[:step_one] = param1
|
182
|
+
ctx[:step_two] = ctx[:step_one]
|
183
|
+
ctx[:step_three] = ctx[:step_two]
|
184
|
+
ctx[:step_four] = ctx[:step_three]
|
185
|
+
ctx[:step_five] = ctx[:step_four]
|
186
|
+
ctx[:step_six] = ctx[:step_five]
|
187
|
+
ctx[:step_seven] = ctx[:step_six]
|
188
|
+
ctx[:step_eight] = ctx[:step_seven]
|
189
|
+
ctx[:step_nine] = ctx[:step_eight]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
class StepOne
|
194
|
+
include Interactor
|
195
|
+
|
196
|
+
def call
|
197
|
+
context.step_one = context.param1
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class StepTwo
|
202
|
+
include Interactor
|
203
|
+
|
204
|
+
def call
|
205
|
+
context.step_two = context.step_one
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
class StepThree
|
210
|
+
include Interactor
|
211
|
+
|
212
|
+
def call
|
213
|
+
context.step_three = context.step_two
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
class StepFour
|
218
|
+
include Interactor
|
219
|
+
|
220
|
+
def call
|
221
|
+
context.step_four = context.step_three
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
class StepFive
|
226
|
+
include Interactor
|
227
|
+
|
228
|
+
def call
|
229
|
+
context.step_five = context.step_four
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
class StepSix
|
234
|
+
include Interactor
|
235
|
+
|
236
|
+
def call
|
237
|
+
context.step_six = context.step_five
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
class StepSeven
|
242
|
+
include Interactor
|
243
|
+
|
244
|
+
def call
|
245
|
+
context.step_seven = context.step_six
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
class StepEight
|
250
|
+
include Interactor
|
251
|
+
|
252
|
+
def call
|
253
|
+
context.step_eight = context.step_seven
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
class StepNine
|
258
|
+
include Interactor
|
259
|
+
|
260
|
+
def call
|
261
|
+
context.step_nine = context.step_eight
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
class InteractorTestOrganizer
|
266
|
+
include Interactor::Organizer
|
267
|
+
|
268
|
+
organize StepOne,
|
269
|
+
StepTwo,
|
270
|
+
StepThree,
|
271
|
+
StepFour,
|
272
|
+
StepFive,
|
273
|
+
StepSix,
|
274
|
+
StepSeven,
|
275
|
+
StepEight,
|
276
|
+
StepNine
|
277
|
+
end
|
278
|
+
|
279
|
+
class InteractorWithoutOrganizer
|
280
|
+
include Interactor
|
281
|
+
|
282
|
+
def call
|
283
|
+
step_one
|
284
|
+
step_two
|
285
|
+
step_three
|
286
|
+
step_four
|
287
|
+
step_five
|
288
|
+
step_six
|
289
|
+
step_seven
|
290
|
+
step_eight
|
291
|
+
step_nine
|
292
|
+
end
|
293
|
+
|
294
|
+
def step_one
|
295
|
+
context.step_one = context.param1
|
296
|
+
end
|
297
|
+
|
298
|
+
def step_two
|
299
|
+
context.step_two = context.step_one
|
300
|
+
end
|
301
|
+
|
302
|
+
def step_three
|
303
|
+
context.step_three = context.step_two
|
304
|
+
end
|
305
|
+
|
306
|
+
def step_four
|
307
|
+
context.step_four = context.step_three
|
308
|
+
end
|
309
|
+
|
310
|
+
def step_five
|
311
|
+
context.step_five = context.step_four
|
312
|
+
end
|
313
|
+
|
314
|
+
def step_six
|
315
|
+
context.step_six = context.step_five
|
316
|
+
end
|
317
|
+
|
318
|
+
def step_seven
|
319
|
+
context.step_seven = context.step_six
|
320
|
+
end
|
321
|
+
|
322
|
+
def step_eight
|
323
|
+
context.step_eight = context.step_seven
|
324
|
+
end
|
325
|
+
|
326
|
+
def step_nine
|
327
|
+
context.step_nine = context.step_eight
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
class RegularServiceTest
|
332
|
+
attr_accessor :ctx, :param1
|
333
|
+
|
334
|
+
def self.call(param1:)
|
335
|
+
new(param1: param1).call
|
336
|
+
end
|
337
|
+
|
338
|
+
def initialize(param1:)
|
339
|
+
@param1 = param1
|
340
|
+
@ctx = {}
|
341
|
+
end
|
342
|
+
|
343
|
+
def call
|
344
|
+
step_one
|
345
|
+
step_two
|
346
|
+
step_three
|
347
|
+
step_four
|
348
|
+
step_five
|
349
|
+
step_six
|
350
|
+
step_seven
|
351
|
+
step_eight
|
352
|
+
step_nine
|
353
|
+
end
|
354
|
+
|
355
|
+
def step_one
|
356
|
+
ctx[:step_one] = param1
|
357
|
+
end
|
358
|
+
|
359
|
+
def step_two
|
360
|
+
ctx[:step_two] = ctx[:step_one]
|
361
|
+
end
|
362
|
+
|
363
|
+
def step_three
|
364
|
+
ctx[:step_three] = ctx[:step_two]
|
365
|
+
end
|
366
|
+
|
367
|
+
def step_four
|
368
|
+
ctx[:step_four] = ctx[:step_three]
|
369
|
+
end
|
370
|
+
|
371
|
+
def step_five
|
372
|
+
ctx[:step_five] = ctx[:step_four]
|
373
|
+
end
|
374
|
+
|
375
|
+
def step_six
|
376
|
+
ctx[:step_six] = ctx[:step_five]
|
377
|
+
end
|
378
|
+
|
379
|
+
def step_seven
|
380
|
+
ctx[:step_seven] = ctx[:step_six]
|
381
|
+
end
|
382
|
+
|
383
|
+
def step_eight
|
384
|
+
ctx[:step_eight] = ctx[:step_seven]
|
385
|
+
end
|
386
|
+
|
387
|
+
def step_nine
|
388
|
+
ctx[:step_nine] = ctx[:step_eight]
|
389
|
+
end
|
390
|
+
end
|
391
|
+
|
392
|
+
class TrailblazerTestSeveralSteps < Trailblazer::Activity::Railway
|
393
|
+
step :step_one
|
394
|
+
step :step_two
|
395
|
+
step :step_three
|
396
|
+
step :step_four
|
397
|
+
step :step_five
|
398
|
+
step :step_six
|
399
|
+
step :step_seven
|
400
|
+
step :step_eight
|
401
|
+
step :step_nine
|
402
|
+
|
403
|
+
def step_one(ctx, param1:, **)
|
404
|
+
ctx[:step_one] = param1
|
405
|
+
end
|
406
|
+
|
407
|
+
def step_two(ctx, step_one:, **)
|
408
|
+
ctx[:step_two] = step_one
|
409
|
+
end
|
410
|
+
|
411
|
+
def step_three(ctx, step_two:, **)
|
412
|
+
ctx[:step_three] = step_two
|
413
|
+
end
|
414
|
+
|
415
|
+
def step_four(ctx, step_three:, **)
|
416
|
+
ctx[:step_four] = step_three
|
417
|
+
end
|
418
|
+
|
419
|
+
def step_five(ctx, step_four:, **)
|
420
|
+
ctx[:step_five] = step_four
|
421
|
+
end
|
422
|
+
|
423
|
+
def step_six(ctx, step_five:, **)
|
424
|
+
ctx[:step_six] = step_five
|
425
|
+
end
|
426
|
+
|
427
|
+
def step_seven(ctx, step_six:, **)
|
428
|
+
ctx[:step_seven] = step_six
|
429
|
+
end
|
430
|
+
|
431
|
+
def step_eight(ctx, step_seven:, **)
|
432
|
+
ctx[:step_eight] = step_seven
|
433
|
+
end
|
434
|
+
|
435
|
+
def step_nine(ctx, step_eight:, **)
|
436
|
+
ctx[:step_nine] = step_eight
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
class TrailblazerTestOneStep < Trailblazer::Activity::Railway
|
441
|
+
step :step_one
|
442
|
+
|
443
|
+
def step_one(ctx, param1:, **)
|
444
|
+
ctx[:step_one] = param1
|
445
|
+
ctx[:step_two] = ctx[:step_one]
|
446
|
+
ctx[:step_three] = ctx[:step_two]
|
447
|
+
ctx[:step_four] = ctx[:step_three]
|
448
|
+
ctx[:step_five] = ctx[:step_four]
|
449
|
+
ctx[:step_six] = ctx[:step_five]
|
450
|
+
ctx[:step_seven] = ctx[:step_six]
|
451
|
+
ctx[:step_eight] = ctx[:step_seven]
|
452
|
+
ctx[:step_nine] = ctx[:step_eight]
|
453
|
+
end
|
454
|
+
end
|
455
|
+
|
456
|
+
iteration_count = 1_000_000
|
457
|
+
|
458
|
+
# result = RubyProf.profile do
|
459
|
+
# iteration_count.times { InteractorTestOrganizer.call(param1: 'param1') }
|
460
|
+
# end
|
461
|
+
|
462
|
+
# class Two
|
463
|
+
# def initialize
|
464
|
+
# @ctx = {}
|
465
|
+
# end
|
466
|
+
|
467
|
+
# def one
|
468
|
+
# @ctx[:one] = 'one'
|
469
|
+
# end
|
470
|
+
|
471
|
+
# def two
|
472
|
+
# @ctx[:two] = @ctx[:one]
|
473
|
+
# end
|
474
|
+
|
475
|
+
# def three
|
476
|
+
# @ctx[:three] = @ctx[:two]
|
477
|
+
# end
|
478
|
+
# end
|
479
|
+
|
480
|
+
# instance = Two.new
|
481
|
+
|
482
|
+
# Benchmark.bmbm do |x|
|
483
|
+
# x.report("PublicSend") { iteration_count.times { instance.public_send(:one) } }
|
484
|
+
# x.report("Send") { iteration_count.times { instance.send(:one) } }
|
485
|
+
# x.report("call instance method") { iteration_count.times { instance.one } }
|
486
|
+
# end
|
487
|
+
|
488
|
+
# array_one = []
|
489
|
+
# array_two = []
|
490
|
+
|
491
|
+
# Benchmark.bmbm do |x|
|
492
|
+
# x.report("<<") { iteration_count.times { array_one << 1 } }
|
493
|
+
# x.report("push") { iteration_count.times { array_two << 1 } }
|
494
|
+
# end
|
495
|
+
|
496
|
+
# result = RubyProf.profile do
|
497
|
+
# iteration_count.times { DecouplioTest.call(param1: 'param1') }
|
498
|
+
# end
|
499
|
+
# result = RubyProf.profile do
|
500
|
+
# iteration_count.times { RegularServiceTest.call(param1: 'param1') }
|
501
|
+
# end
|
502
|
+
# result = RubyProf.profile do
|
503
|
+
# iteration_count.times { TrailblazerTest.call(param1: 'param1') }
|
504
|
+
# end
|
505
|
+
# result = RubyProf.profile do
|
506
|
+
# iteration_count.times { ActiveInteractionTest.run(param1: 'param1') }
|
507
|
+
# end
|
508
|
+
# result = RubyProf.profile do
|
509
|
+
# iteration_count.times { MutationTest.run(param1: 'param1') }
|
510
|
+
# end
|
511
|
+
|
512
|
+
# printer = RubyProf::GraphPrinter.new(result)
|
513
|
+
# printer.print(STDOUT, {})
|
514
|
+
|
515
|
+
Benchmark.bmbm do |x|
|
516
|
+
x.report('RegularService') { iteration_count.times { RegularServiceTest.call(param1: 'param1') } }
|
517
|
+
x.report('Mutation') { iteration_count.times { MutationTest.run(param1: 'param1') } }
|
518
|
+
x.report('ActiveInteraction') { iteration_count.times { ActiveInteractionTest.run(param1: 'param1') } }
|
519
|
+
x.report('Trailblazer one step') { iteration_count.times { TrailblazerTestOneStep.call(param1: 'param1') } }
|
520
|
+
x.report('Interactor one interactor') { iteration_count.times { InteractorWithoutOrganizer.call(param1: 'param1') } }
|
521
|
+
x.report('Decouplio one step') { iteration_count.times { DecouplioTestOneStep.call(param1: 'param1') } }
|
522
|
+
x.report('Trailblazer several steps') { iteration_count.times { TrailblazerTestSeveralSteps.call(param1: 'param1') } }
|
523
|
+
x.report('Interactor several interactions with organizer') do
|
524
|
+
iteration_count.times { InteractorTestOrganizer.call(param1: 'param1') }
|
525
|
+
end
|
526
|
+
x.report('Decouplio several steps') { iteration_count.times { DecouplioTestSeveralSteps.call(param1: 'param1') } }
|
527
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'decouplio'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require 'pry'
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/decouplio.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'decouplio/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'decouplio'
|
9
|
+
spec.version = Decouplio::VERSION
|
10
|
+
spec.authors = ['Alex Bal']
|
11
|
+
spec.email = ['differencialx@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Gem for business logic encapsulation'
|
14
|
+
spec.description = "Decouplio is a zero dependency, thread safe and framework agnostic gem designed to encapsulate application business logic. It's reverse engineered through TDD and inspired by such frameworks and gems like Trailblazer, Interactor."
|
15
|
+
spec.homepage = 'http://nohomepage.com'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/differencialx/decouplio'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/differencialx/decouplio/CHANGELOG.md'
|
22
|
+
else
|
23
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
24
|
+
'public gem pushes.'
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = 'exe'
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ['lib']
|
33
|
+
|
34
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
35
|
+
spec.add_development_dependency 'pry-byebug'
|
36
|
+
spec.add_development_dependency 'rake', '>= 12.3.2'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
|
+
spec.add_development_dependency 'rubocop'
|
39
|
+
spec.add_development_dependency 'rubocop-rspec'
|
40
|
+
end
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
version: "3.7"
|
2
|
+
|
3
|
+
services:
|
4
|
+
benchmark:
|
5
|
+
build:
|
6
|
+
dockerfile: benchmarks/Dockerfile
|
7
|
+
context: .
|
8
|
+
command: "ruby benchmarks.rb"
|
9
|
+
deploy:
|
10
|
+
resources:
|
11
|
+
limits:
|
12
|
+
cpus: '1'
|
13
|
+
memory: 400M
|
14
|
+
test:
|
15
|
+
build:
|
16
|
+
dockerfile: Dockerfile
|
17
|
+
context: .
|
18
|
+
command: "rspec"
|
data/docs/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/docs/benchmarks.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
## Benchmarks
|
data/docs/context.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Context
|
2
|
+
|
3
|
+
Currently context is a simple `Hash` which can be accessed by step methods.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'decouplio'
|
7
|
+
|
8
|
+
class SomeAction < Decouplio::Action
|
9
|
+
logic do
|
10
|
+
step :step_one
|
11
|
+
step :step_two
|
12
|
+
end
|
13
|
+
|
14
|
+
def step_one(**)
|
15
|
+
ctx[:step_one] = 'Step one ctx value'
|
16
|
+
end
|
17
|
+
|
18
|
+
# step method receives ctx as an argument
|
19
|
+
def step_two(step_one:, **)
|
20
|
+
ctx[:step_two] = step_one
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
action = SomeAction.call
|
25
|
+
|
26
|
+
action # =>
|
27
|
+
# Result: success
|
28
|
+
|
29
|
+
# Railway Flow:
|
30
|
+
# step_one -> step_two
|
31
|
+
|
32
|
+
# Context:
|
33
|
+
# {:step_one=>"Step one ctx value", :step_two=>"Step one ctx value"}
|
34
|
+
|
35
|
+
# Errors:
|
36
|
+
# {}
|
37
|
+
```
|
38
|
+
|
39
|
+
All key values passed into `call` method will be automatically assigned to action context.
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'decouplio'
|
43
|
+
|
44
|
+
class SomeActionCtx < Decouplio::Action
|
45
|
+
logic do
|
46
|
+
step :step_one
|
47
|
+
end
|
48
|
+
|
49
|
+
def step_one(**)
|
50
|
+
puts ctx
|
51
|
+
ctx[:result] = ctx[:one] + ctx[:two]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
action = SomeActionCtx.call(
|
56
|
+
one: 1,
|
57
|
+
two: 2
|
58
|
+
) # =>
|
59
|
+
# {:one=>1, :two=>2}
|
60
|
+
|
61
|
+
action[:result] # => 3
|
62
|
+
|
63
|
+
action # =>
|
64
|
+
# Result: success
|
65
|
+
|
66
|
+
# Railway Flow:
|
67
|
+
# step_one
|
68
|
+
|
69
|
+
# Context:
|
70
|
+
# {:one=>1, :two=>2, :result=>3}
|
71
|
+
|
72
|
+
# Errors:
|
73
|
+
# {}
|
74
|
+
```
|