opera 0.2.3 → 0.2.7
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/CHANGELOG.md +17 -0
- data/Gemfile.lock +1 -1
- data/README.md +63 -0
- data/lib/opera/operation/base.rb +7 -1
- data/lib/opera/operation/builder.rb +1 -1
- data/lib/opera/operation/executor.rb +2 -0
- data/lib/opera/operation/instructions/executors/finish_if.rb +16 -0
- data/lib/opera/operation/result.rb +4 -0
- data/lib/opera/operation.rb +1 -1
- data/lib/opera/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5bbb67e42e162ac6cbea3ac242a707d270110035cf618f84ea8cc5e33a60de8
|
4
|
+
data.tar.gz: 512a3bf21c0a6e686e41e9eb25ed21634612f4e004bd7ece8c3e3177664bcbcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d55665d552e5be5d23f150d17f121700b958fc8dfdd92ef1c4cc82d9d4329b03e8a4c08c8204bff87897e65d0c2858c06df8677748b9a437795476e47b6dd62
|
7
|
+
data.tar.gz: 939e7abdc56c89ff03131ff98d9721dde54224891711923073bc5377a7389f46c660b7a8f909e13204ec74f565be6217a21c12e00e522dc18ecf1cbff42a6dc6
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,22 @@
|
|
1
1
|
# Opera Changelog
|
2
2
|
|
3
|
+
### 0.2.7 - October 29, 2021
|
4
|
+
|
5
|
+
- Adds `finish_if` step to DSL
|
6
|
+
|
7
|
+
### 0.2.6 - October 29, 2021
|
8
|
+
|
9
|
+
- New method Result#failures that returns combined errors and exceptions
|
10
|
+
|
11
|
+
### 0.2.5 - August 3, 2021
|
12
|
+
|
13
|
+
- make sure that `default` option in accessors is always lambda
|
14
|
+
|
15
|
+
### 0.2.4 - July 26, 2021
|
16
|
+
|
17
|
+
- prevent default from overwrite falsy values
|
18
|
+
- allow params and dependencies to get defaults
|
19
|
+
|
3
20
|
### 0.2.3 - July 26, 2021
|
4
21
|
|
5
22
|
- Support context, params and dependencies accessors
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -144,6 +144,8 @@ end
|
|
144
144
|
|
145
145
|
[Success](#user-content-success)
|
146
146
|
|
147
|
+
[Finish if](#user-content-finish-if)
|
148
|
+
|
147
149
|
[Inner Operation](#user-content-inner-operation)
|
148
150
|
|
149
151
|
[Inner Operations](#user-content-inner-operations)
|
@@ -712,6 +714,67 @@ Profile::Create.call(params: {
|
|
712
714
|
#<Opera::Operation::Result:0x007fd0248e5638 @errors={"mailer"=>["Missing dependency"]}, @exceptions={}, @information={}, @executions=[:profile_schema, :populate, :create, :update, :send_email, :output], @output={:model=>#<Profile id: 40, user_id: nil, linkedin_uid: nil, picture: nil, headline: nil, summary: nil, first_name: "foo", last_name: "bar", created_at: "2019-01-03 12:21:35", updated_at: "2019-01-02 12:21:35", agree_to_terms_and_conditions: nil, registration_status: "", account_id: 1, start_date: nil, supervisor_id: nil, picture_processing: false, statistics: {}, data: {}, notification_timestamps: {}, suggestions: {}, notification_settings: {}, contact_information: []>}>
|
713
715
|
```
|
714
716
|
|
717
|
+
### Finish If
|
718
|
+
|
719
|
+
```ruby
|
720
|
+
class Profile::Create < Opera::Operation::Base
|
721
|
+
context_accessor :profile
|
722
|
+
dependencies_reader :current_account, :mailer
|
723
|
+
|
724
|
+
validate :profile_schema
|
725
|
+
|
726
|
+
step :create
|
727
|
+
finish_if :profile_create_only
|
728
|
+
step :update
|
729
|
+
|
730
|
+
success do
|
731
|
+
step :send_email
|
732
|
+
step :output
|
733
|
+
end
|
734
|
+
|
735
|
+
def profile_schema
|
736
|
+
Dry::Validation.Schema do
|
737
|
+
required(:first_name).filled
|
738
|
+
end.call(params)
|
739
|
+
end
|
740
|
+
|
741
|
+
def create
|
742
|
+
self.profile = current_account.profiles.create(params)
|
743
|
+
end
|
744
|
+
|
745
|
+
def profile_create_only
|
746
|
+
dependencies[:create_only].present?
|
747
|
+
end
|
748
|
+
|
749
|
+
def update
|
750
|
+
profile.update(updated_at: 1.day.ago)
|
751
|
+
end
|
752
|
+
|
753
|
+
# NOTE: We can add an error in this step and it won't break the execution
|
754
|
+
def send_email
|
755
|
+
result.add_error('mailer', 'Missing dependency')
|
756
|
+
mailer&.send_mail(profile: profile)
|
757
|
+
end
|
758
|
+
|
759
|
+
def output
|
760
|
+
result.output = { model: context[:profile] }
|
761
|
+
end
|
762
|
+
end
|
763
|
+
```
|
764
|
+
|
765
|
+
#### Example with information (real and total) from benchmark
|
766
|
+
|
767
|
+
```ruby
|
768
|
+
Profile::Create.call(params: {
|
769
|
+
first_name: :foo,
|
770
|
+
last_name: :bar
|
771
|
+
}, dependencies: {
|
772
|
+
create_only: true,
|
773
|
+
current_account: Account.find(1)
|
774
|
+
})
|
775
|
+
#<Opera::Operation::Result:0x007fd0248e5638 @errors={}, @exceptions={}, @information={}, @executions=[:profile_schema, :create, :profile_create_only], @output={}>
|
776
|
+
```
|
777
|
+
|
715
778
|
### Inner Operation
|
716
779
|
|
717
780
|
```ruby
|
data/lib/opera/operation/base.rb
CHANGED
@@ -60,7 +60,13 @@ module Opera
|
|
60
60
|
check_method_availability!(attribute)
|
61
61
|
|
62
62
|
define_method(attribute) do
|
63
|
-
send(method)[attribute]
|
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
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Opera
|
4
4
|
module Operation
|
5
5
|
module Builder
|
6
|
-
INSTRUCTIONS = %I[validate transaction benchmark step success operation operations].freeze
|
6
|
+
INSTRUCTIONS = %I[validate transaction benchmark step success finish_if operation operations].freeze
|
7
7
|
|
8
8
|
def self.included(base)
|
9
9
|
base.extend(ClassMethods)
|
@@ -46,6 +46,8 @@ module Opera
|
|
46
46
|
Instructions::Executors::Transaction.new(operation).call(instruction)
|
47
47
|
when :benchmark
|
48
48
|
Instructions::Executors::Benchmark.new(operation).call(instruction)
|
49
|
+
when :finish_if
|
50
|
+
Instructions::Executors::FinishIf.new(operation).call(instruction)
|
49
51
|
else
|
50
52
|
raise(UnknownInstructionError, "Unknown instruction #{instruction[:kind]}")
|
51
53
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Opera
|
4
|
+
module Operation
|
5
|
+
module Instructions
|
6
|
+
module Executors
|
7
|
+
class FinishIf < Executor
|
8
|
+
def call(instruction)
|
9
|
+
instruction[:kind] = :step
|
10
|
+
operation.finish! if super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/opera/operation.rb
CHANGED
@@ -8,6 +8,7 @@ require 'opera/operation/config'
|
|
8
8
|
require 'opera/operation/instructions/executors/success'
|
9
9
|
require 'opera/operation/instructions/executors/transaction'
|
10
10
|
require 'opera/operation/instructions/executors/benchmark'
|
11
|
+
require 'opera/operation/instructions/executors/finish_if'
|
11
12
|
require 'opera/operation/instructions/executors/validate'
|
12
13
|
require 'opera/operation/instructions/executors/operation'
|
13
14
|
require 'opera/operation/instructions/executors/operations'
|
@@ -15,6 +16,5 @@ require 'opera/operation/instructions/executors/step'
|
|
15
16
|
|
16
17
|
module Opera
|
17
18
|
module Operation
|
18
|
-
|
19
19
|
end
|
20
20
|
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.7
|
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-
|
11
|
+
date: 2021-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/opera/operation/config.rb
|
85
85
|
- lib/opera/operation/executor.rb
|
86
86
|
- lib/opera/operation/instructions/executors/benchmark.rb
|
87
|
+
- lib/opera/operation/instructions/executors/finish_if.rb
|
87
88
|
- lib/opera/operation/instructions/executors/operation.rb
|
88
89
|
- lib/opera/operation/instructions/executors/operations.rb
|
89
90
|
- lib/opera/operation/instructions/executors/step.rb
|