use_cases 2.0.3 → 2.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/use_cases/module_optins/locked.rb +54 -0
- data/lib/use_cases/module_optins/validated.rb +3 -3
- data/lib/use_cases/module_optins.rb +2 -0
- data/lib/use_cases/step_adapters/abstract.rb +1 -1
- data/lib/use_cases/version.rb +1 -1
- data/lib/use_cases.rb +5 -2
- 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: 002cd8e4ba47c0fc98bc6ebc94e0c9dfad03c05dd2ccbd2160b4ea738329e8a7
|
4
|
+
data.tar.gz: b57f81ed1f63f054125288084ab40dd77e429e8fc88a71de3f642eacb71c210e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cec0558bc4e44c59c5af5b7abb31379c266fc6007a4f52c9b86df41eb99ee439c3447775a01dfc6090fac9887c70a76db8a3f14b774a54cf1f54308b862da4a
|
7
|
+
data.tar.gz: 6b38fcf05bb719e8f9ae864647b721bf34c1aeb99253ba8548140cb8e52f9e8adce96a9545ab5dbdc09702b549a65c183cd9559d693c969485fcfc7bc189eaef
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "use_cases/step_adapters/check"
|
4
|
+
|
5
|
+
module UseCases
|
6
|
+
module ModuleOptins
|
7
|
+
module Locked
|
8
|
+
def self.included(base)
|
9
|
+
super
|
10
|
+
base.class_eval do
|
11
|
+
extend DSL
|
12
|
+
prepend CallPatch
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
MissingLockConfiguration = Class.new(StandardError)
|
17
|
+
MissingLockerError = Class.new(StandardError)
|
18
|
+
|
19
|
+
module DSL
|
20
|
+
attr_reader :_lock_with, :_lock_options
|
21
|
+
|
22
|
+
def lock_with(options = {}, &blk)
|
23
|
+
@_lock_with = blk || options.delete(:key)
|
24
|
+
@_lock_options = options
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module CallPatch
|
29
|
+
def call(*args)
|
30
|
+
unless self.class._lock_with
|
31
|
+
raise MissingLockConfiguration, "Locked use cases require setting `lock_with` to define the cache key and wait configuration.\n" \
|
32
|
+
" Example: `lock_with { |params, curent_user| \"my-key-\#{params[:id]}-\#{curent_user.id}\" }`"
|
33
|
+
end
|
34
|
+
|
35
|
+
key = lock_with(*args)
|
36
|
+
|
37
|
+
raise MissingLockerError, "Locked use cases require setting `locker` dependency to define the cache store.\n" unless respond_to?(:locker)
|
38
|
+
|
39
|
+
locker.lock(key, lock_options) { super }
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def lock_options
|
45
|
+
self.class._lock_options
|
46
|
+
end
|
47
|
+
|
48
|
+
def lock_with(*args)
|
49
|
+
self.class._lock_with.is_a?(Proc) ? self.class._lock_with.call(*args) : self.class._lock_with
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -58,9 +58,9 @@ module UseCases
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def block_with_config(&blk)
|
61
|
-
|
61
|
+
proc do
|
62
62
|
instance_exec(&UseCases.dry_validation)
|
63
|
-
instance_exec(&blk)
|
63
|
+
instance_exec(&blk)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -76,7 +76,7 @@ module UseCases
|
|
76
76
|
params.merge!(validation.to_h)
|
77
77
|
Success(validation.to_h)
|
78
78
|
else
|
79
|
-
Failure([:validation_error, UseCases.transform_validation_errors.(validation.errors)])
|
79
|
+
Failure([:validation_error, UseCases.transform_validation_errors.call(validation.errors)])
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -4,6 +4,7 @@ require "use_cases/module_optins/prepared"
|
|
4
4
|
require "use_cases/module_optins/transactional"
|
5
5
|
require "use_cases/module_optins/validated"
|
6
6
|
require "use_cases/module_optins/authorized"
|
7
|
+
require "use_cases/module_optins/locked"
|
7
8
|
|
8
9
|
module UseCases
|
9
10
|
module ModuleOptins
|
@@ -14,6 +15,7 @@ module UseCases
|
|
14
15
|
transactional: Transactional,
|
15
16
|
validated: Validated,
|
16
17
|
prepared: Prepared,
|
18
|
+
locked: Locked
|
17
19
|
}.freeze
|
18
20
|
|
19
21
|
def [](*options)
|
data/lib/use_cases/version.rb
CHANGED
data/lib/use_cases.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.6
|
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-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -149,6 +149,7 @@ files:
|
|
149
149
|
- lib/use_cases/dsl.rb
|
150
150
|
- lib/use_cases/module_optins.rb
|
151
151
|
- lib/use_cases/module_optins/authorized.rb
|
152
|
+
- lib/use_cases/module_optins/locked.rb
|
152
153
|
- lib/use_cases/module_optins/prepared.rb
|
153
154
|
- lib/use_cases/module_optins/transactional.rb
|
154
155
|
- lib/use_cases/module_optins/validated.rb
|