opera 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -4
- data/Gemfile.lock +2 -2
- data/README.md +81 -46
- data/lib/opera/operation/base.rb +35 -7
- data/lib/opera/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c87b8365cd3d9a0da8fce865abe9babe04df29df31253697ec01bf45ee81d897
|
4
|
+
data.tar.gz: 313ba34f1abc8e4845b71a4b1f209362ad14c08d79dd30a51b120c52e364ee2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42bdbac9178ca00ea91d998c5d1ee20a125993bc5ac830d5e5f523092527a40d1948a5504b5120d88b72200272994c71839cb2ea6d4361cd1a7402d8e9e76c16
|
7
|
+
data.tar.gz: 1ba960d0d599d5cfc9c0d0c5e788420043fb8bbc4c1608f806bc751b9e4b0dd00744fd3a10a200957ff9fcce7c300c508ca27c5b2d6da3b022601dfb9587dbee
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
# Opera Changelog
|
2
2
|
|
3
|
-
|
3
|
+
### 0.2.3 - July 26, 2021
|
4
4
|
|
5
|
-
-
|
5
|
+
- Support context, params and dependencies accessors
|
6
|
+
- Removed depreceted `finish` method. Please use `finish!` from today
|
7
|
+
|
8
|
+
## 0.2.2 - July 7, 2021
|
9
|
+
|
10
|
+
- Test release using Github Actions
|
6
11
|
|
7
12
|
## 0.2.1 - July 7, 2021
|
8
13
|
|
9
14
|
- Support for transaction options
|
10
15
|
|
11
|
-
## 0.
|
16
|
+
## 0.1.0 - September 12, 2020
|
12
17
|
|
13
|
-
-
|
18
|
+
- Initial release
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Opera
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/opera.svg)](https://badge.fury.io/rb/opera)
|
3
4
|
![Master](https://github.com/Profinda/opera/actions/workflows/release.yml/badge.svg?branch=master)
|
4
5
|
|
5
6
|
|
@@ -155,6 +156,9 @@ Some cases and example how to use new operations
|
|
155
156
|
|
156
157
|
```ruby
|
157
158
|
class Profile::Create < Opera::Operation::Base
|
159
|
+
context_accessor :profile
|
160
|
+
dependencies_reader :current_account, :mailer
|
161
|
+
|
158
162
|
validate :profile_schema
|
159
163
|
|
160
164
|
step :create
|
@@ -168,15 +172,15 @@ class Profile::Create < Opera::Operation::Base
|
|
168
172
|
end
|
169
173
|
|
170
174
|
def create
|
171
|
-
|
175
|
+
self.profile = current_account.profiles.create(params)
|
172
176
|
end
|
173
177
|
|
174
178
|
def send_email
|
175
|
-
|
179
|
+
mailer&.send_mail(profile: profile)
|
176
180
|
end
|
177
181
|
|
178
182
|
def output
|
179
|
-
result.output = { model:
|
183
|
+
result.output = { model: profile }
|
180
184
|
end
|
181
185
|
end
|
182
186
|
```
|
@@ -225,6 +229,9 @@ Profile::Create.call(params: {
|
|
225
229
|
|
226
230
|
```ruby
|
227
231
|
class Profile::Create < Opera::Operation::Base
|
232
|
+
context_accessor :profile
|
233
|
+
dependencies_reader :current_account, :mailer
|
234
|
+
|
228
235
|
validate :profile_schema
|
229
236
|
|
230
237
|
step :create
|
@@ -240,16 +247,17 @@ class Profile::Create < Opera::Operation::Base
|
|
240
247
|
end
|
241
248
|
|
242
249
|
def create
|
243
|
-
|
250
|
+
self.profile = current_account.profiles.create(context[:profile_schema_output])
|
244
251
|
end
|
245
252
|
|
246
253
|
def send_email
|
247
|
-
return true unless
|
248
|
-
|
254
|
+
return true unless mailer
|
255
|
+
|
256
|
+
mailer.send_mail(profile: profile)
|
249
257
|
end
|
250
258
|
|
251
259
|
def output
|
252
|
-
result.output = { model:
|
260
|
+
result.output = { model: profile }
|
253
261
|
end
|
254
262
|
end
|
255
263
|
```
|
@@ -271,6 +279,9 @@ Profile::Create.call(params: {
|
|
271
279
|
|
272
280
|
```ruby
|
273
281
|
class Profile::Create < Opera::Operation::Base
|
282
|
+
context_accessor :profile
|
283
|
+
dependencies_reader :current_account, :mailer
|
284
|
+
|
274
285
|
validate :profile_schema
|
275
286
|
|
276
287
|
step :build_record
|
@@ -286,29 +297,29 @@ class Profile::Create < Opera::Operation::Base
|
|
286
297
|
end
|
287
298
|
|
288
299
|
def build_record
|
289
|
-
|
290
|
-
|
300
|
+
self.profile = current_account.profiles.build(params)
|
301
|
+
self.profile.force_name_validation = true
|
291
302
|
end
|
292
303
|
|
293
304
|
def old_validation
|
294
|
-
return true if
|
305
|
+
return true if profile.valid?
|
295
306
|
|
296
307
|
result.add_information(missing_validations: "Please check dry validations")
|
297
|
-
result.add_errors(
|
308
|
+
result.add_errors(profile.errors.messages)
|
298
309
|
|
299
310
|
false
|
300
311
|
end
|
301
312
|
|
302
313
|
def create
|
303
|
-
|
314
|
+
profile.save
|
304
315
|
end
|
305
316
|
|
306
317
|
def send_email
|
307
|
-
|
318
|
+
mailer.send_mail(profile: profile)
|
308
319
|
end
|
309
320
|
|
310
321
|
def output
|
311
|
-
result.output = { model:
|
322
|
+
result.output = { model: profile }
|
312
323
|
end
|
313
324
|
end
|
314
325
|
```
|
@@ -344,6 +355,9 @@ Profile::Create.call(params: {
|
|
344
355
|
|
345
356
|
```ruby
|
346
357
|
class Profile::Create < Opera::Operation::Base
|
358
|
+
context_accessor :profile
|
359
|
+
dependencies_reader :current_account, :mailer
|
360
|
+
|
347
361
|
validate :profile_schema
|
348
362
|
|
349
363
|
step :build_record
|
@@ -359,8 +373,8 @@ class Profile::Create < Opera::Operation::Base
|
|
359
373
|
end
|
360
374
|
|
361
375
|
def build_record
|
362
|
-
|
363
|
-
|
376
|
+
self.profile = current_account.profiles.build(params)
|
377
|
+
self.profile.force_name_validation = true
|
364
378
|
end
|
365
379
|
|
366
380
|
def exception
|
@@ -368,21 +382,23 @@ class Profile::Create < Opera::Operation::Base
|
|
368
382
|
end
|
369
383
|
|
370
384
|
def create
|
371
|
-
|
385
|
+
self.profile = profile.save
|
372
386
|
end
|
373
387
|
|
374
388
|
def send_email
|
375
|
-
return true unless
|
389
|
+
return true unless mailer
|
376
390
|
|
377
|
-
|
391
|
+
mailer.send_mail(profile: profile)
|
378
392
|
end
|
379
393
|
|
380
394
|
def output
|
381
|
-
result.output(model:
|
395
|
+
result.output(model: profile)
|
382
396
|
end
|
383
397
|
end
|
384
398
|
```
|
399
|
+
|
385
400
|
##### Call with step throwing exception
|
401
|
+
|
386
402
|
```ruby
|
387
403
|
result = Profile::Create.call(params: {
|
388
404
|
first_name: :foo,
|
@@ -398,6 +414,9 @@ result = Profile::Create.call(params: {
|
|
398
414
|
|
399
415
|
```ruby
|
400
416
|
class Profile::Create < Opera::Operation::Base
|
417
|
+
context_accessor :profile
|
418
|
+
dependencies_reader :current_account, :mailer
|
419
|
+
|
401
420
|
validate :profile_schema
|
402
421
|
|
403
422
|
step :build_record
|
@@ -412,27 +431,29 @@ class Profile::Create < Opera::Operation::Base
|
|
412
431
|
end
|
413
432
|
|
414
433
|
def build_record
|
415
|
-
|
416
|
-
|
434
|
+
self.profile = current_account.profiles.build(params)
|
435
|
+
self.profile.force_name_validation = true
|
417
436
|
end
|
418
437
|
|
419
438
|
def create
|
420
|
-
|
421
|
-
finish
|
439
|
+
self.profile = profile.save
|
440
|
+
finish!
|
422
441
|
end
|
423
442
|
|
424
443
|
def send_email
|
425
|
-
return true unless
|
444
|
+
return true unless mailer
|
426
445
|
|
427
|
-
|
446
|
+
mailer.send_mail(profile: profile)
|
428
447
|
end
|
429
448
|
|
430
449
|
def output
|
431
|
-
result.output(model:
|
450
|
+
result.output(model: profile)
|
432
451
|
end
|
433
452
|
end
|
434
453
|
```
|
454
|
+
|
435
455
|
##### Call
|
456
|
+
|
436
457
|
```ruby
|
437
458
|
result = Profile::Create.call(params: {
|
438
459
|
first_name: :foo,
|
@@ -452,6 +473,9 @@ class Profile::Create < Opera::Operation::Base
|
|
452
473
|
config.transaction_class = Profile
|
453
474
|
end
|
454
475
|
|
476
|
+
context_accessor :profile
|
477
|
+
dependencies_reader :current_account, :mailer
|
478
|
+
|
455
479
|
validate :profile_schema
|
456
480
|
|
457
481
|
transaction do
|
@@ -469,21 +493,21 @@ class Profile::Create < Opera::Operation::Base
|
|
469
493
|
end
|
470
494
|
|
471
495
|
def create
|
472
|
-
|
496
|
+
self.profile = current_account.profiles.create(params)
|
473
497
|
end
|
474
498
|
|
475
499
|
def update
|
476
|
-
|
500
|
+
profile.update(example_attr: :Example)
|
477
501
|
end
|
478
502
|
|
479
503
|
def send_email
|
480
|
-
return true unless
|
504
|
+
return true unless mailer
|
481
505
|
|
482
|
-
|
506
|
+
mailer.send_mail(profile: profile)
|
483
507
|
end
|
484
508
|
|
485
509
|
def output
|
486
|
-
result.output = { model:
|
510
|
+
result.output = { model: profile }
|
487
511
|
end
|
488
512
|
end
|
489
513
|
```
|
@@ -514,6 +538,9 @@ class Profile::Create < Opera::Operation::Base
|
|
514
538
|
config.transaction_class = Profile
|
515
539
|
end
|
516
540
|
|
541
|
+
context_accessor :profile
|
542
|
+
dependencies_reader :current_account, :mailer
|
543
|
+
|
517
544
|
validate :profile_schema
|
518
545
|
|
519
546
|
transaction do
|
@@ -531,21 +558,21 @@ class Profile::Create < Opera::Operation::Base
|
|
531
558
|
end
|
532
559
|
|
533
560
|
def create
|
534
|
-
|
561
|
+
self.profile = current_account.profiles.create(params)
|
535
562
|
end
|
536
563
|
|
537
564
|
def update
|
538
|
-
|
565
|
+
profile.update(updated_at: 1.day.ago)
|
539
566
|
end
|
540
567
|
|
541
568
|
def send_email
|
542
|
-
return true unless
|
569
|
+
return true unless mailer
|
543
570
|
|
544
|
-
|
571
|
+
mailer.send_mail(profile: profile)
|
545
572
|
end
|
546
573
|
|
547
574
|
def output
|
548
|
-
result.output = { model:
|
575
|
+
result.output = { model: profile }
|
549
576
|
end
|
550
577
|
end
|
551
578
|
```
|
@@ -572,6 +599,9 @@ D, [2020-08-17T12:10:44.898132 #2741] DEBUG -- : (10.3ms) COMMIT
|
|
572
599
|
|
573
600
|
```ruby
|
574
601
|
class Profile::Create < Opera::Operation::Base
|
602
|
+
context_accessor :profile
|
603
|
+
dependencies_reader :current_account, :mailer
|
604
|
+
|
575
605
|
validate :profile_schema
|
576
606
|
|
577
607
|
step :create
|
@@ -589,21 +619,21 @@ class Profile::Create < Opera::Operation::Base
|
|
589
619
|
end
|
590
620
|
|
591
621
|
def create
|
592
|
-
|
622
|
+
self.profile = current_account.profiles.create(params)
|
593
623
|
end
|
594
624
|
|
595
625
|
def update
|
596
|
-
|
626
|
+
profile.update(updated_at: 1.day.ago)
|
597
627
|
end
|
598
628
|
|
599
629
|
def send_email
|
600
|
-
return true unless
|
630
|
+
return true unless mailer
|
601
631
|
|
602
|
-
|
632
|
+
mailer.send_mail(profile: profile)
|
603
633
|
end
|
604
634
|
|
605
635
|
def output
|
606
|
-
result.output = { model:
|
636
|
+
result.output = { model: profile }
|
607
637
|
end
|
608
638
|
end
|
609
639
|
```
|
@@ -624,6 +654,9 @@ Profile::Create.call(params: {
|
|
624
654
|
|
625
655
|
```ruby
|
626
656
|
class Profile::Create < Opera::Operation::Base
|
657
|
+
context_accessor :profile
|
658
|
+
dependencies_reader :current_account, :mailer
|
659
|
+
|
627
660
|
validate :profile_schema
|
628
661
|
|
629
662
|
success :populate
|
@@ -648,17 +681,17 @@ class Profile::Create < Opera::Operation::Base
|
|
648
681
|
end
|
649
682
|
|
650
683
|
def create
|
651
|
-
|
684
|
+
self.profile = current_account.profiles.create(params)
|
652
685
|
end
|
653
686
|
|
654
687
|
def update
|
655
|
-
|
688
|
+
profile.update(updated_at: 1.day.ago)
|
656
689
|
end
|
657
690
|
|
658
691
|
# NOTE: We can add an error in this step and it won't break the execution
|
659
692
|
def send_email
|
660
693
|
result.add_error('mailer', 'Missing dependency')
|
661
|
-
|
694
|
+
mailer&.send_mail(profile: profile)
|
662
695
|
end
|
663
696
|
|
664
697
|
def output
|
@@ -791,6 +824,8 @@ Opera::Operation::Result.new(output: 'success')
|
|
791
824
|
|
792
825
|
## Opera::Operation::Base - Class Methods
|
793
826
|
>
|
827
|
+
- context_[reader|writer|accessor] - predefined methods for easy access
|
828
|
+
- [params|dependencies]_reader - predefined readers for immutable arguments
|
794
829
|
- step(Symbol) - single instruction
|
795
830
|
- return [Truthly] - continue operation execution
|
796
831
|
- return [False] - stops operation execution
|
@@ -810,7 +845,7 @@ Opera::Operation::Result.new(output: 'success')
|
|
810
845
|
- context [Hash] - used to pass information between steps - only for internal usage
|
811
846
|
- params [Hash] - immutable and received in call method
|
812
847
|
- dependencies [Hash] - immutable and received in call method
|
813
|
-
- finish
|
848
|
+
- finish! - this method interrupts the execution of steps after is invoked
|
814
849
|
|
815
850
|
## Development
|
816
851
|
|
data/lib/opera/operation/base.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
module Opera
|
4
4
|
module Operation
|
5
5
|
class Base
|
6
|
-
extend Gem::Deprecate
|
7
6
|
include Opera::Operation::Builder
|
8
7
|
|
9
8
|
attr_accessor :context
|
@@ -21,12 +20,6 @@ module Opera
|
|
21
20
|
self.class.config
|
22
21
|
end
|
23
22
|
|
24
|
-
def finish
|
25
|
-
finish!
|
26
|
-
end
|
27
|
-
|
28
|
-
deprecate :finish, :finish!, 2019, 6
|
29
|
-
|
30
23
|
def finish!
|
31
24
|
@finished = true
|
32
25
|
end
|
@@ -54,6 +47,41 @@ module Opera
|
|
54
47
|
def reporter
|
55
48
|
config.reporter
|
56
49
|
end
|
50
|
+
|
51
|
+
def check_method_availability!(method)
|
52
|
+
return if instance_methods(false).none?(method)
|
53
|
+
|
54
|
+
raise(ArgumentError, "Method #{method} is already defined")
|
55
|
+
end
|
56
|
+
|
57
|
+
%i[context params dependencies].each do |method|
|
58
|
+
define_method("#{method}_reader") do |*attributes, **options|
|
59
|
+
attributes.map(&:to_sym).each do |attribute|
|
60
|
+
check_method_availability!(attribute)
|
61
|
+
|
62
|
+
define_method(attribute) do
|
63
|
+
send(method)[attribute] ||= options[:default]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
%i[context].each do |method|
|
70
|
+
define_method("#{method}_writer") do |*attributes|
|
71
|
+
attributes.map(&:to_sym).each do |attribute|
|
72
|
+
check_method_availability!("#{attribute}=")
|
73
|
+
|
74
|
+
define_method("#{attribute}=") do |value|
|
75
|
+
send(method)[attribute] = value
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
define_method("#{method}_accessor") do |*attributes, **options|
|
81
|
+
send("#{method}_reader", *attributes, **options)
|
82
|
+
send("#{method}_writer", *attributes)
|
83
|
+
end
|
84
|
+
end
|
57
85
|
end
|
58
86
|
end
|
59
87
|
end
|
data/lib/opera/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ProFinda Development Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|