use_cases 2.0.3 → 2.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0e64ac5284a76952a2d0da6e2d48ea40b93af03926b5f4d0a23a38698836dfe0
4
- data.tar.gz: b9c894909398b9cc287da875175f125319243b0dd077158d27b59e498e184cbe
3
+ metadata.gz: 002cd8e4ba47c0fc98bc6ebc94e0c9dfad03c05dd2ccbd2160b4ea738329e8a7
4
+ data.tar.gz: b57f81ed1f63f054125288084ab40dd77e429e8fc88a71de3f642eacb71c210e
5
5
  SHA512:
6
- metadata.gz: a34740d4caa9274eeed8e76ebc20293c3dc1e962551b35b3c14b885e018135d51a7f27f832b9ca02b0639a6bf4e4e4febcf4567bd7ed6531077940e709f9e84f
7
- data.tar.gz: 728d1da8f92f9d375b11172fc68f4b8aab7e4b9efa048a88959bd9996d327a27bda9432948fdd82d8dcae0fab05a64e4127efb343441b7d4f0e8e5b66d1ed31b
6
+ metadata.gz: 8cec0558bc4e44c59c5af5b7abb31379c266fc6007a4f52c9b86df41eb99ee439c3447775a01dfc6090fac9887c70a76db8a3f14b774a54cf1f54308b862da4a
7
+ data.tar.gz: 6b38fcf05bb719e8f9ae864647b721bf34c1aeb99253ba8548140cb8e52f9e8adce96a9545ab5dbdc09702b549a65c183cd9559d693c969485fcfc7bc189eaef
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- use_cases (2.0.3)
4
+ use_cases (2.0.6)
5
5
  activesupport (>= 5.1)
6
6
  dry-matcher (>= 0.8.1)
7
7
  dry-monads (>= 1.0.0)
@@ -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
- Proc.new do
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)
@@ -47,7 +47,7 @@ module UseCases
47
47
  {
48
48
  previous_step_result: prev_result,
49
49
  params: params,
50
- current_user: current_user,
50
+ current_user: current_user
51
51
  }.slice(*pass_option)
52
52
  end
53
53
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UseCases
4
- VERSION = "2.0.3"
4
+ VERSION = "2.0.6"
5
5
  end
data/lib/use_cases.rb CHANGED
@@ -23,8 +23,11 @@ module UseCases
23
23
  def self.dry_validation
24
24
  config_proc = config.dry_validation
25
25
 
26
- Proc.new do
27
- config_proc.call(config)
26
+ proc do
27
+ begin
28
+ config_proc.call(config)
29
+ rescue Dry::Configurable::FrozenConfig
30
+ end
28
31
  end
29
32
  end
30
33
  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: 2.0.3
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-09-22 00:00:00.000000000 Z
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