effective_resources 1.18.10 → 1.19.0

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: c513100225a155db0f3922dbfcecfda7dc40b94b98746273053f35c2bf6c5d0b
4
- data.tar.gz: 3669286a34fe2c0304d1a10a74e446279a7600f88766687e9e7cdbd06cbdc8f9
3
+ metadata.gz: 2ee4ff2d3193e327ddaa6fd457d83df4342e1ccfd1a5a0d2d06525ee5e8b5ce3
4
+ data.tar.gz: 63c5eebe27c1f4a49fba71dd2e1b69a92ce73faa35c915f53f77b4fca8dc8beb
5
5
  SHA512:
6
- metadata.gz: f10ad3eafe4170593b01a684f8c68dfdbffa8748fbc61ef60892385b2d4d8e12eddb1d1b3855c6bc99afa56f33631a1e238b6485e7b5daa7f8a7678d0f457514
7
- data.tar.gz: 37f1b0a1c9d54da6783641729225f18815d60aa7d78e1ea07d86897e855a8b527317763a62c6bc36f393f2ea8eaf62837d432d217c8076c2d90d3c7ce8f4c0ee
6
+ metadata.gz: d6f2209d606a8e800f9d9b715b06dfbe1d230f73dd429728257d2f7b2876211bba08a5111cf992a9ed20c92f8d320bf62a2cae994c550d8e27b354e4ea602c3d
7
+ data.tar.gz: 7d78f999628f819a663debe59ffd1799c1b8caeaafb264e4fe986b90f23a573d63d019612e83b455c75fb2741510367f706015b9c5587b0b24b731e3b398286a
@@ -29,44 +29,43 @@ module Effective
29
29
  end
30
30
 
31
31
  success = false
32
+ exception = nil
32
33
 
33
- EffectiveResources.transaction(resource) do
34
- begin
35
- run_callbacks(:resource_before_save)
34
+ begin
35
+ ActiveRecord::Base.transaction do
36
+ EffectiveResources.transaction(resource) do
37
+ run_callbacks(:resource_before_save)
36
38
 
37
- if resource.public_send("#{save_action}!") == false
38
- raise Effective::ActionFailed.new("failed to #{action}")
39
- end
39
+ if resource.public_send("#{save_action}!") == false
40
+ raise Effective::ActionFailed.new("failed to #{action}")
41
+ end
40
42
 
41
- yield if block_given?
43
+ yield if block_given?
42
44
 
43
- run_callbacks(:resource_after_save)
45
+ run_callbacks(:resource_after_save)
44
46
 
45
- success = true
46
- rescue => e
47
- if Rails.env.development?
48
- Rails.logger.info " \e[31m\e[1mFAILED\e[0m\e[22m" # bold red
49
- Rails.logger.info " Unable to #{action} #{resource} - #{e.class} #{e}"
50
- e.backtrace.first(5).each { |line| Rails.logger.info(' ' + line) }
47
+ success = true
48
+ rescue Effective::ActionFailed => e
49
+ exception = e # Dont rollback
51
50
  end
51
+ end
52
+ rescue => e
53
+ exception = e
54
+ end
52
55
 
53
- if resource.respond_to?(:restore_attributes) && resource.persisted?
54
- resource.restore_attributes(['status', 'state'])
55
- end
56
+ if exception.present?
57
+ Rails.logger.info " \e[31m\e[1mFAILED\e[0m\e[22m" # bold red
58
+ Rails.logger.info " Unable to #{action} #{resource} - #{e.class} #{e}"
59
+ exception.backtrace.first(5).each { |line| Rails.logger.info(' ' + line) }
56
60
 
57
- flash.now[:danger] = resource_flash(:danger, resource, action, e: e)
58
-
59
- case e
60
- when ActiveRecord::StaleObjectError
61
- flash.now[:danger] = "#{flash.now[:danger]} <a href='#', class='alert-link' onclick='window.location.reload(true); return false;'>reload page and try again</a>"
62
- raise(ActiveRecord::Rollback) # This is a soft error, we want to display the flash message to user
63
- when Effective::ActionFailed
64
- # Nothing to do
65
- when ActiveRecord::RecordInvalid, RuntimeError
66
- raise(ActiveRecord::Rollback) # This is a soft error, we want to display the flash message to user
67
- else
68
- raise(e) # This is a real error that should be sent to 500. Client should not see the message.
69
- end
61
+ if resource.respond_to?(:restore_attributes) && resource.persisted?
62
+ resource.restore_attributes(['status', 'state'])
63
+ end
64
+
65
+ flash.now[:danger] = resource_flash(:danger, resource, action, e: e)
66
+
67
+ if exception.kind_of?(ActiveRecord::StaleObjectError)
68
+ flash.now[:danger] = "#{flash.now[:danger]} <a href='#', class='alert-link' onclick='window.location.reload(true); return false;'>reload page and try again</a>"
70
69
  end
71
70
  end
72
71
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.18.10'.freeze
2
+ VERSION = '1.19.0'.freeze
3
3
  end
@@ -87,10 +87,7 @@ module EffectiveResources
87
87
  end
88
88
 
89
89
  def self.transaction(resource = nil, &block)
90
- connection = 'ActiveRecord::Base'.safe_constantize
91
- raise('unable to determine transaction class') unless connection.present?
92
-
93
- connection.transaction { yield }
90
+ resource.class.transaction { yield }
94
91
  end
95
92
 
96
93
  # Used by streaming CSV export in datatables
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: 1.18.10
4
+ version: 1.19.0
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-12 00:00:00.000000000 Z
11
+ date: 2022-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails