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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad99f05ab646eaf5777374411ea3cee95a7d6809a4dd1c9110ddd78b248e0a9
|
4
|
+
data.tar.gz: 79a500fabc0110e16298f4031004655ba2d317413a1df90eb31390add344745f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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]
|
data/lib/effective_resources.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2022-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|