effective_resources 2.0.0 → 2.0.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: f9da0a46c6938d58b83a1da33cf0a198c8f4f53f7c3bb4b96ee5467160c06370
4
- data.tar.gz: 6435ce69271ba313f1d02642d16ad24791cd4c2ea99e14be06782ceb4cc409e2
3
+ metadata.gz: aad99f05ab646eaf5777374411ea3cee95a7d6809a4dd1c9110ddd78b248e0a9
4
+ data.tar.gz: 79a500fabc0110e16298f4031004655ba2d317413a1df90eb31390add344745f
5
5
  SHA512:
6
- metadata.gz: b35a6f53cd730eec70f2010332cbfd44c7e311b4341cf033b2b490069341b0e9fdad5bd607209b6ef63e1e9695dfcd5490b72d14a293aceed31159cacd2a30c9
7
- data.tar.gz: bea48fa8d635bbed0d2786b52c70b09a7e35629177bcda6f5218f1d7c83db5c1fe964f88243468d22b2753ee0a74223b6d3e91d47e67e8f5320a202bdb8942f5
6
+ metadata.gz: 211a18be0391a97797bab8d502ca0295c70cbe1d4a11da84e06fcf6f4187b1da9f027f85bda0cb513b6a4089d566f3698676ef973f4458ab7218bb2aebcb57ee
7
+ data.tar.gz: 87612647fbde94ec96a736c2c462b22021c644ef7496aa3feb7b1da63f15baf83337ca002ebf9c920112e7c43caaf9b9351ff5b73712fefc8b62a61e723eba49
@@ -228,7 +228,7 @@ module Effective
228
228
 
229
229
  # No attributes are assigned or saved. We purely call action! on the resource
230
230
 
231
- EffectiveResources.transaction do
231
+ ActiveRecord::Base.transaction do
232
232
  successes = resources.select do |resource|
233
233
  begin
234
234
  resource.public_send("#{action}!") if EffectiveResources.authorized?(self, action, resource)
@@ -33,7 +33,7 @@ module Effective
33
33
 
34
34
  begin
35
35
  ActiveRecord::Base.transaction do
36
- resource.transaction do
36
+ EffectiveResources.transaction(resource) do
37
37
  run_callbacks(:resource_before_save)
38
38
 
39
39
  if resource.public_send("#{save_action}!") == false
@@ -49,8 +49,11 @@ module Effective
49
49
  exception = e # Dont rollback
50
50
  end
51
51
  end
52
+ rescue ActiveRecord::RecordInvalid => e
53
+ exception = e
52
54
  rescue => e
53
55
  exception = e
56
+ notify_exception(e, resource, action) unless e.class.name == 'RuntimeError'
54
57
  end
55
58
 
56
59
  if exception.present?
@@ -74,6 +77,14 @@ module Effective
74
77
  success
75
78
  end
76
79
 
80
+ def notify_exception(exception, resource, action)
81
+ if defined?(ExceptionNotifier)
82
+ ExceptionNotifier.notify_exception(exception, env: request.env, data: { resource: resource, action: action })
83
+ else
84
+ raise(exception)
85
+ end
86
+ end
87
+
77
88
  def resource_flash(status, resource, action, e: nil)
78
89
  submit = commit_action(action)
79
90
  message = submit[status].respond_to?(:call) ? instance_exec(&submit[status]) : submit[status]
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.2'.freeze
3
3
  end
@@ -159,4 +159,17 @@ module EffectiveResources
159
159
  duplicate
160
160
  end
161
161
 
162
+ def self.transaction(resource = nil, &block)
163
+ raise('expected a block') unless block_given?
164
+
165
+ if resource.respond_to?(:transaction)
166
+ resource.transaction { yield }
167
+ elsif resource.class.respond_to?(:transaction)
168
+ resource.class.transaction { yield }
169
+ else
170
+ ActiveRecord::Base.transaction { yield }
171
+ end
172
+
173
+ end
174
+
162
175
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-28 00:00:00.000000000 Z
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails