effective_resources 1.18.9 → 1.19.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: 5cee67d7d1f8986997b77f0a8d4d2f50cd7b0344ec84522dea0980df07662098
4
- data.tar.gz: 07bd05a2149368657239d5ed7abd4cce69a3d84b761f81f2653353c3cb4441d3
3
+ metadata.gz: 2ee4ff2d3193e327ddaa6fd457d83df4342e1ccfd1a5a0d2d06525ee5e8b5ce3
4
+ data.tar.gz: 63c5eebe27c1f4a49fba71dd2e1b69a92ce73faa35c915f53f77b4fca8dc8beb
5
5
  SHA512:
6
- metadata.gz: 395ca8155e668c86d1060901f9106f155d8202d0f235aac7ec8ef9e497b45b6b02386ec6e6e127615a3291640514508f2ccdbbc3696a1ff41c050ad83289b10e
7
- data.tar.gz: 4d264db3c46fb74607fc31094a435e3b7c6db1895639f7a425ae65b971a0a051e0f09e1ad5ff059c38d3f5f36e243734302205a29fb6a703ac274847578da9e5
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
 
@@ -9,8 +9,8 @@ module EffectiveActsAsEmailFormHelper
9
9
  raise('expected an acts_as_email_form resource') unless resource.class.respond_to?(:acts_as_email_form?)
10
10
 
11
11
  # Load the template.
12
- email_template = if action.present? && resource.email_form_effective_email_templates?
13
- Effective::EmailTemplate.where(template_name: action).first!
12
+ email_template = if action.present? && defined?(EffectiveEmailTemplates)
13
+ action.kind_of?(Effective::EmailTemplate) ? action : Effective::EmailTemplate.where(template_name: action).first!
14
14
  end
15
15
 
16
16
  # These defaults are only used when there is no email_template
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.18.9'.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.9
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-01 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