use_cases 1.1.1 → 1.1.2

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: c61b0fc85c1ed9ffdee1bc0f03b6991a7fcd9b64bb502e5b6859e5e124865068
4
- data.tar.gz: b99383f71920f2c376e2bb197e4a7be3140630b36dcd33b3169bc15582adc5ac
3
+ metadata.gz: 1acf28555c44f6ddde193195d340f9ea4dc9d3ffce2ec9ad5302d626bc3fa07a
4
+ data.tar.gz: eebecd33d8f5f64e0fc73e1174e7e32b7252d88f1c2de8543297ec3fd78fbab4
5
5
  SHA512:
6
- metadata.gz: 93f9d4b5b4f7492ac49d142b51336b6837c3ad8ff54706a1fa363bd851bd6f7d366e6131bb5e8399ef32de8e38608c07f33c8794ab7cb5fd571e6450b8f866f6
7
- data.tar.gz: ea72716e2909d65ec10904df231262ba6104cab8e564eb99129f1ba2adfaf2a43b1e93b5ab7c1285aa3e72f76d52b9440e65ce2c7a5a903ae191685f4bee3a39
6
+ metadata.gz: 9e728db5f63082ce761579c57bf3b9ab22a2059d5720823bfda3c90105b60be10dc7e93ad7d0c87cef7b848bbc2ffd061a4cd806e386c030b34b39c04974ae12
7
+ data.tar.gz: 7f04086052168ba6af1933d2e196fbb4e5053188270b72f3ebf245007863be40695aa10d3dc98c7ea53845c3f88bebb68d35f5a316f39203b36e0906694623df
@@ -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)
@@ -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
 
@@ -74,7 +81,9 @@ module UseCases
74
81
  end
75
82
 
76
83
  def contract
77
- return self.class._contract_class.new if self.class._contract_class_defined?
84
+ return unless self.class._contract_class_defined?
85
+
86
+ self.class._contract_class.new
78
87
  end
79
88
 
80
89
  module ClassMethods
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UseCases
4
- VERSION = "1.1.1"
4
+ VERSION = "1.1.2"
5
5
  end
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,13 @@ 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
+
23
+ def self.dry_validation
24
+ config_proc = config.dry_validation
25
+
26
+ Proc.new do
27
+ config_proc.call(config)
28
+ end
29
+ end
20
30
  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.1
4
+ version: 1.1.2
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-02-14 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport