opera 0.2.1 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1289d8fac87c7236cf48c043f9901589bbc04965946fac600d5b056d850c006e
4
- data.tar.gz: 8aa8a43aeb813b0f388a2f49e814b924426685ac7a00d5b0b224df29f740aea6
3
+ metadata.gz: e5d9c893a5fbb54c998d21da587625c5c4395325cba2e626daaecc7a09c8dfcb
4
+ data.tar.gz: 718d329ba4593be294625339bf7803764c3daba1b6af28d44bbd0d466d5bc0ac
5
5
  SHA512:
6
- metadata.gz: e759a1bde5f394fb1baa50c7f268f2c094b2321c57536a3a10ba6a909800736fc31a98b8fdec1bf786626693e4a7e65e7f0a1806665d5d962b5a257f10af8aea
7
- data.tar.gz: 4cc58219c20a9f11a2bfad9e9963a0254951609e93ef698b6d89a37a10a55adc5aa1684472b15efbdb82909aa8eadcbbdd0b7c21d85be6573cc8a67da6de29c5
6
+ metadata.gz: 723969ac97c573f821395a239ed57fb4fcd8f39ab8ffe7f1d492c848b4625ab7e2b6a1e6a1460cddf5500fa1a486bb43aa6849e2d7bbd1e984ba915321f9aeff
7
+ data.tar.gz: eb67bdc92c6d8f6156566e00bae3da4b7cbe9ea7eb7911c287952726fae6b3d703258efe495ef9fcfcdb4b847b2593358d859e72426a75e1ce2fec70017091b8
@@ -0,0 +1,66 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+
7
+ jobs:
8
+ test:
9
+ runs-on: ubuntu-latest
10
+ strategy:
11
+ matrix:
12
+ ruby-version: [ '2.6', '2.7', '3.0' ]
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby
17
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
18
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
19
+ # uses: ruby/setup-ruby@v1
20
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
21
+ with:
22
+ ruby-version: ${{ matrix.ruby-version }}
23
+ bundler-cache: false # runs 'bundle install' and caches installed gems automatically
24
+ - name: Install gems
25
+ run: bundle install
26
+ - name: Run tests
27
+ run: bundle exec rspec
28
+
29
+ tag:
30
+ needs: test
31
+ runs-on: ubuntu-latest
32
+
33
+ steps:
34
+ - uses: actions/checkout@v2
35
+
36
+ - name: Tag automatically
37
+ run: git tag v`cat lib/opera/version.rb | grep 'VERSION' | awk '{ print $3 $4 }' | sed "s/'//g"`
38
+
39
+ - name: Push tags
40
+ run: git push origin --tags
41
+
42
+ publish:
43
+ needs: tag
44
+ name: Build + Publish
45
+ runs-on: ubuntu-latest
46
+ permissions:
47
+ contents: read
48
+ packages: write
49
+
50
+ steps:
51
+ - uses: actions/checkout@v2
52
+ - name: Set up Ruby 2.6
53
+ uses: actions/setup-ruby@v1
54
+ with:
55
+ ruby-version: 2.6.x
56
+
57
+ - name: Publish to RubyGems
58
+ run: |
59
+ mkdir -p $HOME/.gem
60
+ touch $HOME/.gem/credentials
61
+ chmod 0600 $HOME/.gem/credentials
62
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
63
+ gem build *.gemspec
64
+ gem push *.gem
65
+ env:
66
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -8,14 +8,11 @@
8
8
  name: Specs
9
9
 
10
10
  on:
11
- push:
12
- branches: [ master ]
13
11
  pull_request:
14
12
  branches: []
15
13
 
16
14
  jobs:
17
15
  test:
18
-
19
16
  runs-on: ubuntu-latest
20
17
  strategy:
21
18
  matrix:
data/CHANGELOG.md CHANGED
@@ -1,9 +1,27 @@
1
1
  # Opera Changelog
2
2
 
3
- ## 0.1.0 - September 12, 2020
3
+ ### 0.2.5 - August 3, 2021
4
4
 
5
- - Initial release
5
+ - make sure that `default` option in accessors is always lambda
6
+
7
+ ### 0.2.4 - July 26, 2021
8
+
9
+ - prevent default from overwrite falsy values
10
+ - allow params and dependencies to get defaults
11
+
12
+ ### 0.2.3 - July 26, 2021
13
+
14
+ - Support context, params and dependencies accessors
15
+ - Removed depreceted `finish` method. Please use `finish!` from today
16
+
17
+ ## 0.2.2 - July 7, 2021
18
+
19
+ - Test release using Github Actions
6
20
 
7
21
  ## 0.2.1 - July 7, 2021
8
22
 
9
23
  - Support for transaction options
24
+
25
+ ## 0.1.0 - September 12, 2020
26
+
27
+ - Initial release
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opera (0.1.2)
4
+ opera (0.2.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -81,4 +81,4 @@ DEPENDENCIES
81
81
  rspec (~> 3.0)
82
82
 
83
83
  BUNDLED WITH
84
- 2.1.4
84
+ 2.2.15
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Opera
2
2
 
3
- ![Master](https://github.com/Profinda/opera/actions/workflows/ruby.yml/badge.svg?branch=master)
3
+ [![Gem Version](https://badge.fury.io/rb/opera.svg)](https://badge.fury.io/rb/opera)
4
+ ![Master](https://github.com/Profinda/opera/actions/workflows/release.yml/badge.svg?branch=master)
4
5
 
5
6
 
6
7
  Simple DSL for services/interactions classes.
@@ -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
- context[:profile] = dependencies[:current_account].profiles.create(params)
175
+ self.profile = current_account.profiles.create(params)
172
176
  end
173
177
 
174
178
  def send_email
175
- dependencies[:mailer]&.send_mail(profile: context[:profile])
179
+ mailer&.send_mail(profile: profile)
176
180
  end
177
181
 
178
182
  def output
179
- result.output = { model: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.create(context[:profile_schema_output])
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 dependencies[:mailer]
248
- dependencies[:mailer].send_mail(profile: context[:profile])
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: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.build(params)
290
- context[:profile].force_name_validation = true
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 context[:profile].valid?
305
+ return true if profile.valid?
295
306
 
296
307
  result.add_information(missing_validations: "Please check dry validations")
297
- result.add_errors(context[:profile].errors.messages)
308
+ result.add_errors(profile.errors.messages)
298
309
 
299
310
  false
300
311
  end
301
312
 
302
313
  def create
303
- context[:profile].save
314
+ profile.save
304
315
  end
305
316
 
306
317
  def send_email
307
- dependencies[:mailer].send_mail(profile: context[:profile])
318
+ mailer.send_mail(profile: profile)
308
319
  end
309
320
 
310
321
  def output
311
- result.output = { model: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.build(params)
363
- context[:profile].force_name_validation = true
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
- context[:profile] = context[:profile].save
385
+ self.profile = profile.save
372
386
  end
373
387
 
374
388
  def send_email
375
- return true unless dependencies[:mailer]
389
+ return true unless mailer
376
390
 
377
- dependencies[:mailer].send_mail(profile: context[:profile])
391
+ mailer.send_mail(profile: profile)
378
392
  end
379
393
 
380
394
  def output
381
- result.output(model: context[:profile])
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
- context[:profile] = dependencies[:current_account].profiles.build(params)
416
- context[:profile].force_name_validation = true
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
- context[:profile] = context[:profile].save
421
- finish
439
+ self.profile = profile.save
440
+ finish!
422
441
  end
423
442
 
424
443
  def send_email
425
- return true unless dependencies[:mailer]
444
+ return true unless mailer
426
445
 
427
- dependencies[:mailer].send_mail(profile: context[:profile])
446
+ mailer.send_mail(profile: profile)
428
447
  end
429
448
 
430
449
  def output
431
- result.output(model: context[:profile])
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
- context[:profile] = dependencies[:current_account].profiles.create(params)
496
+ self.profile = current_account.profiles.create(params)
473
497
  end
474
498
 
475
499
  def update
476
- context[:profile].update(example_attr: :Example)
500
+ profile.update(example_attr: :Example)
477
501
  end
478
502
 
479
503
  def send_email
480
- return true unless dependencies[:mailer]
504
+ return true unless mailer
481
505
 
482
- dependencies[:mailer].send_mail(profile: context[:profile])
506
+ mailer.send_mail(profile: profile)
483
507
  end
484
508
 
485
509
  def output
486
- result.output = { model: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.create(params)
561
+ self.profile = current_account.profiles.create(params)
535
562
  end
536
563
 
537
564
  def update
538
- context[:profile].update(updated_at: 1.day.ago)
565
+ profile.update(updated_at: 1.day.ago)
539
566
  end
540
567
 
541
568
  def send_email
542
- return true unless dependencies[:mailer]
569
+ return true unless mailer
543
570
 
544
- dependencies[:mailer].send_mail(profile: context[:profile])
571
+ mailer.send_mail(profile: profile)
545
572
  end
546
573
 
547
574
  def output
548
- result.output = { model: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.create(params)
622
+ self.profile = current_account.profiles.create(params)
593
623
  end
594
624
 
595
625
  def update
596
- context[:profile].update(updated_at: 1.day.ago)
626
+ profile.update(updated_at: 1.day.ago)
597
627
  end
598
628
 
599
629
  def send_email
600
- return true unless dependencies[:mailer]
630
+ return true unless mailer
601
631
 
602
- dependencies[:mailer].send_mail(profile: context[:profile])
632
+ mailer.send_mail(profile: profile)
603
633
  end
604
634
 
605
635
  def output
606
- result.output = { model: context[:profile] }
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
- context[:profile] = dependencies[:current_account].profiles.create(params)
684
+ self.profile = current_account.profiles.create(params)
652
685
  end
653
686
 
654
687
  def update
655
- context[:profile].update(updated_at: 1.day.ago)
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
- dependencies[:mailer]&.send_mail(profile: context[:profile])
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 - this method interrupts the execution of steps after is invoked
848
+ - finish! - this method interrupts the execution of steps after is invoked
814
849
 
815
850
  ## Development
816
851
 
@@ -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,47 @@ 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
+ value = send(method).key?(attribute) ? send(method)[attribute] : self.instance_exec(&options[:default])
64
+
65
+ if send(method).frozen?
66
+ send(method)[attribute] || value
67
+ else
68
+ send(method)[attribute] ||= value
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ %i[context].each do |method|
76
+ define_method("#{method}_writer") do |*attributes|
77
+ attributes.map(&:to_sym).each do |attribute|
78
+ check_method_availability!("#{attribute}=")
79
+
80
+ define_method("#{attribute}=") do |value|
81
+ send(method)[attribute] = value
82
+ end
83
+ end
84
+ end
85
+
86
+ define_method("#{method}_accessor") do |*attributes, **options|
87
+ send("#{method}_reader", *attributes, **options)
88
+ send("#{method}_writer", *attributes)
89
+ end
90
+ end
57
91
  end
58
92
  end
59
93
  end
data/lib/opera/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Opera
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.5'
3
3
  end
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.1
4
+ version: 0.2.5
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-07 00:00:00.000000000 Z
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation
@@ -59,9 +59,8 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".github/workflows/gem-push.yml"
62
+ - ".github/workflows/release.yml"
63
63
  - ".github/workflows/specs.yml"
64
- - ".github/workflows/tag.yml"
65
64
  - ".gitignore"
66
65
  - ".rspec"
67
66
  - ".travis.yml"
@@ -1,31 +0,0 @@
1
- name: Ruby Gem
2
-
3
- on:
4
- push:
5
- branches: [ master ]
6
-
7
- jobs:
8
- build:
9
- name: Build + Publish
10
- runs-on: ubuntu-latest
11
- permissions:
12
- contents: read
13
- packages: write
14
-
15
- steps:
16
- - uses: actions/checkout@v2
17
- - name: Set up Ruby 2.6
18
- uses: actions/setup-ruby@v1
19
- with:
20
- ruby-version: 2.6.x
21
-
22
- - name: Publish to RubyGems
23
- run: |
24
- mkdir -p $HOME/.gem
25
- touch $HOME/.gem/credentials
26
- chmod 0600 $HOME/.gem/credentials
27
- printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
28
- gem build *.gemspec
29
- gem push *.gem
30
- env:
31
- GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
@@ -1,22 +0,0 @@
1
- # This is a basic workflow to help you get started with Actions
2
-
3
- name: Tag
4
-
5
- # Controls when the workflow will run
6
- on:
7
- # Triggers the workflow on push or pull request events but only for the master branch
8
- push:
9
- branches: [ master ]
10
-
11
- jobs:
12
- build:
13
- runs-on: ubuntu-latest
14
-
15
- steps:
16
- - uses: actions/checkout@v2
17
-
18
- - name: Tag automatically
19
- run: git tag v`cat lib/opera/version.rb | grep 'VERSION' | awk '{ print $3 $4 }' | sed "s/'//g"`
20
-
21
- - name: Push tags
22
- run: git push origin --tags