use_cases 1.1.1 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/use_cases/module_optins/publishing.rb +5 -3
- data/lib/use_cases/module_optins/validated.rb +16 -7
- data/lib/use_cases/version.rb +1 -1
- data/lib/use_cases.rb +11 -0
- 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: 34892c434db7409635d2628aee340dc76f71f2386c3b28c591b958d3fd7b9581
|
4
|
+
data.tar.gz: 922c959f22bbf32c82de1913a6384d46058eec701274dcaaee8dd5cb63fc09df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d2da877b7f1e0ad6e9cc01a560126110b8e53e9e1364b1cea07943318380c766499890b0bec5b67d8c3687742489f902cade0f76761cf6da693942cf01cc9c7
|
7
|
+
data.tar.gz: db808f18bb859f6f9faa2ac6aac8c6f5dcee9e820235e35b74bf5074fe262f7b477e2aa344c9d14d815b6739c2b47f7b530f3fdb8c84bf61c8f6407e41c6e237
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -68,7 +68,7 @@ end
|
|
68
68
|
|---|---|
|
69
69
|
| `:authorized` | Adds an extra `authorize` step macro, used to check user permissions. |
|
70
70
|
| `:prepared` | Adds an extra `prepare` step macro, used to run some code before the use case runs. |
|
71
|
-
| `:publishing` | Adds extra extra `publish`
|
71
|
+
| `:publishing` | Adds extra extra `publish`, `event_data` and `event_metadata` options to all steps, which allows a step to broadcast an event after executing |
|
72
72
|
| `:transactional` | Calls `#transaction` on a given `transaction_handler` object around the use case execution |
|
73
73
|
| `:validated` | Adds all methods of `dry-transaction` to the use case DSL, which run validations on the received `params` object. |
|
74
74
|
|
@@ -122,7 +122,7 @@ class Users::DeleteAccount
|
|
122
122
|
|
123
123
|
authorize :user_owns_account?, failure_message: 'Cannot delete account'
|
124
124
|
try :load_account, catch: ActiveRecord::RecordNotFound, failure: :account_not_found, failure_message: 'Account not found'
|
125
|
-
map :delete_account, publish: :account_deleted
|
125
|
+
map :delete_account, publish: :account_deleted, event_data: proc { |account| { account_id: account.id } }, event_metadata: proc { { published_by: 'users.delete_account' } }
|
126
126
|
enqueue :send_farewell_email
|
127
127
|
|
128
128
|
private
|
@@ -16,6 +16,8 @@ module UseCases
|
|
16
16
|
module StepPatch
|
17
17
|
def initialize(*)
|
18
18
|
super
|
19
|
+
return unless options[:publish]
|
20
|
+
|
19
21
|
%w[success failure].map do |event_type|
|
20
22
|
event_id = [options[:publish], event_type].join(".")
|
21
23
|
Events::EventRegistry.register(event_id)
|
@@ -40,10 +42,10 @@ module UseCases
|
|
40
42
|
private
|
41
43
|
|
42
44
|
def extract_payload(step_result, args)
|
45
|
+
value = step_result.value!
|
43
46
|
{
|
44
|
-
|
45
|
-
|
46
|
-
current_user: args[-1]
|
47
|
+
data: options[:event_data]&.call(value, args) || {},
|
48
|
+
metadata: options[:event_metadata]&.call(value, args) || {}
|
47
49
|
}
|
48
50
|
end
|
49
51
|
|
@@ -32,29 +32,36 @@ module UseCases
|
|
32
32
|
def params(*args, &blk)
|
33
33
|
_setup_validation
|
34
34
|
|
35
|
-
_contract_class.params(*args, &blk)
|
35
|
+
_contract_class.params(*args, &block_with_config(&blk))
|
36
36
|
end
|
37
37
|
|
38
38
|
def schema(*args, &blk)
|
39
39
|
_setup_validation
|
40
40
|
|
41
|
-
_contract_class.schema(*args, &blk)
|
41
|
+
_contract_class.schema(*args, &block_with_config(&blk))
|
42
42
|
end
|
43
43
|
|
44
44
|
def rule(*args, &blk)
|
45
45
|
_setup_validation
|
46
46
|
|
47
|
-
_contract_class.rule(*args, &blk)
|
47
|
+
_contract_class.rule(*args, &block_with_config(&blk))
|
48
48
|
end
|
49
49
|
|
50
50
|
def json(*args, &blk)
|
51
51
|
_setup_validation
|
52
52
|
|
53
|
-
_contract_class.json(*args, &blk)
|
53
|
+
_contract_class.json(*args, &block_with_config(&blk))
|
54
54
|
end
|
55
55
|
|
56
56
|
def option(*args, &blk)
|
57
|
-
_contract_class.option(*args, &blk)
|
57
|
+
_contract_class.option(*args, &block_with_config(&blk))
|
58
|
+
end
|
59
|
+
|
60
|
+
def block_with_config(&blk)
|
61
|
+
Proc.new do
|
62
|
+
instance_exec(&UseCases.dry_validation)
|
63
|
+
instance_exec(&blk)
|
64
|
+
end
|
58
65
|
end
|
59
66
|
end
|
60
67
|
|
@@ -69,12 +76,14 @@ module UseCases
|
|
69
76
|
params.merge!(validation.to_h)
|
70
77
|
Success(validation.to_h)
|
71
78
|
else
|
72
|
-
Failure([:validation_error, validation.errors
|
79
|
+
Failure([:validation_error, UseCases.transform_validation_errors.(validation.errors)])
|
73
80
|
end
|
74
81
|
end
|
75
82
|
|
76
83
|
def contract
|
77
|
-
return
|
84
|
+
return unless self.class._contract_class_defined?
|
85
|
+
|
86
|
+
self.class._contract_class.new
|
78
87
|
end
|
79
88
|
|
80
89
|
module ClassMethods
|
data/lib/use_cases/version.rb
CHANGED
data/lib/use_cases.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "dry/configurable"
|
4
|
+
require "dry/types"
|
4
5
|
|
5
6
|
require_relative "use_case"
|
6
7
|
require_relative "use_cases/version"
|
@@ -17,4 +18,14 @@ module UseCases
|
|
17
18
|
setting :container, reader: true
|
18
19
|
setting :publisher, default: ::UseCases::Events::Publisher.new, reader: true
|
19
20
|
setting :subscribers, default: [], reader: true
|
21
|
+
setting :dry_validation, default: ->(config) {}
|
22
|
+
setting :transform_validation_errors, default: ->(errors) { errors.to_h }, reader: true
|
23
|
+
|
24
|
+
def self.dry_validation
|
25
|
+
config_proc = config.dry_validation
|
26
|
+
|
27
|
+
Proc.new do
|
28
|
+
config_proc.call(config)
|
29
|
+
end
|
30
|
+
end
|
20
31
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: use_cases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ring Twice
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -143,6 +143,7 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
+
- ".github/dependabot.yml"
|
146
147
|
- ".github/workflows/main.yml"
|
147
148
|
- ".gitignore"
|
148
149
|
- ".rspec"
|