activeinteractor 2.0.0.alpha.1.0.0 → 2.0.0.alpha.2.1.0

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: b84d76be97bd543c4583c588b6f7dae50424c640fa675b7a4fb154bc8bdb1051
4
- data.tar.gz: c0846db96ac34ed824b79118395afea967e528f4b8eb797eb7411c156ddb5d55
3
+ metadata.gz: 8353806528fdb9ad9625f469d16d400929d9ef3cae024490c85982354f4d9bad
4
+ data.tar.gz: af9cfad32cffe177d1b30fa7fb482f3305a6757152090d82482aef39f448a628
5
5
  SHA512:
6
- metadata.gz: 2ce8f776d073318c6bfdc47e6d822febde4570aa4777eab9ff2096bac4e8162a5849e01b929f8ed4e33f04b45edeca018e9a7381e651a3ec1556b68826c2e891
7
- data.tar.gz: 822f52d219f12aaec5f373e1eed23f70568b3dd44972eda16f6a2c27f03fb1895b3566d605602448443db263765dae6e0b7a0c2e1dfdd0f61d0392c92c064977
6
+ metadata.gz: 45a07cd05ee5ad9e27fb23f2ebe1a99c5bc01cdeeda5987e35a501b22230ecb56ea49ccc36c233348a838a6c25cd2fa8b6945326bef13839d1f4541a0d3ac043
7
+ data.tar.gz: c11cbf40fa73910ce12a43a60db15f13983ec6174006627eae29eecd068002be2fcbd50b7062d4cd0d955736594a246611f66c570db59b152e889053c9b5128d
@@ -7,8 +7,12 @@ module ActiveInteractor
7
7
  attributes[:arguments][name.to_sym] = { name: name, type: type, description: description }.merge(options)
8
8
  end
9
9
 
10
+ def perform!(input_context = {})
11
+ new(input_context).perform!
12
+ end
13
+
10
14
  def perform(input_context = {})
11
- new(input_context).send(:exec_perform!)
15
+ perform!(input_context)
12
16
  rescue Error => e
13
17
  e.result
14
18
  rescue StandardError => e
@@ -31,21 +35,37 @@ module ActiveInteractor
31
35
  @context = parse_input!
32
36
  end
33
37
 
34
- def perform; end
38
+ def perform!
39
+ with_notification(:perform) do |payload|
40
+ interact
41
+ payload[:result] = Result.success(data: parse_output!)
42
+ end
43
+ end
44
+
45
+ def perform
46
+ perform!
47
+ rescue Error => e
48
+ e.result
49
+ rescue StandardError => e
50
+ Result.failure(errors: e.message)
51
+ end
52
+
53
+ def interact; end
35
54
  def rollback; end
36
55
 
37
56
  protected
38
57
 
39
58
  attr_accessor :context
40
59
 
41
- def exec_perform!
42
- perform
43
- Result.success(data: parse_output!)
44
- end
45
-
46
60
  def fail!(errors = {})
47
- rollback
48
- raise Error, Result.failure(data: context, errors: errors)
61
+ result = nil
62
+ with_notification(:rollback) do |payload|
63
+ rollback
64
+ result = Result.failure(data: parse_output!, errors: errors)
65
+ payload[:result] = result
66
+ end
67
+
68
+ raise Error, result
49
69
  end
50
70
 
51
71
  def parse_input!
@@ -79,5 +99,11 @@ module ActiveInteractor
79
99
  errors[attribute_name] << :blank
80
100
  errors
81
101
  end
102
+
103
+ def with_notification(action)
104
+ ActiveSupport::Notifications.instrument("#{self.class.name}::#{action.to_s.classify}") do |payload|
105
+ yield payload if block_given?
106
+ end
107
+ end
82
108
  end
83
109
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'active_model'
4
4
  require 'active_support'
5
+ require 'active_support/core_ext'
5
6
 
6
7
  require_relative 'active_interactor/errors'
7
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeinteractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha.1.0.0
4
+ version: 2.0.0.alpha.2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Allen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-10 00:00:00.000000000 Z
11
+ date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -72,9 +72,9 @@ licenses:
72
72
  - MIT
73
73
  metadata:
74
74
  bug_tracker_uri: https://github.com/activeinteractor/activeinteractor/issues
75
- changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.1.0.0/CHANGELOG.md
75
+ changelog_uri: https://github.com/activeinteractor/activeinteractor/blob/v2.0.0-alpha.2.1.0/CHANGELOG.md
76
76
  homepage_uri: https://github.com/activeinteractor/activeinteractor
77
- source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.1.0.0
77
+ source_code_uri: https://github.com/activeinteractor/activeinteractor/tree/v2.0.0-alpha.2.1.0
78
78
  wiki_uri: https://github.com/activeinteractor/activeinteractor/wiki
79
79
  rubygems_mfa_required: 'true'
80
80
  post_install_message: