effective_resources 1.8.23 → 1.8.24
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ef5eba619e3764fdc204b3e1b72ec0063b16c2319866688f4c8e7ff3808354d
|
4
|
+
data.tar.gz: '09e02f90c4db8a1f0f416ec6ece7471db4e9ab865a4bac701a4977c9c6f4e18a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65b2ec2e37dd19c24375b02533b86519733d83652b24fc131f267d625de17bdd0210efea61ca84e7186e2b3b0d5821a94e7faf1805665bf752c0b2636456eb8f
|
7
|
+
data.tar.gz: 8bf7c81fd895011224ffa0ed49942bf3c8517ca7e7a2c8141820247c859014de9fa1eed17517b25ed5951bff7d904c091b165d4ab1f2710ad8e674c34d9a8d06
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# EffectiveAfterCommit
|
2
|
+
#
|
3
|
+
# Inspired by https://github.com/Envek/after_commit_everywhere
|
4
|
+
#
|
5
|
+
# This is automatically included into ActiveRecord::Base
|
6
|
+
#
|
7
|
+
# after_commit { MyMailer.welcome.deliver_later }
|
8
|
+
|
9
|
+
module EffectiveAfterCommit
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
module Base
|
13
|
+
def after_commit(connection: self.class.connection, &callback)
|
14
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback, no_tx_action: :execute)
|
15
|
+
end
|
16
|
+
|
17
|
+
def before_commit(connection: self.class.connection, &callback)
|
18
|
+
raise(NotImplementedError, "#{__method__} works only with Rails 5.0+") if ActiveRecord::VERSION::MAJOR < 5
|
19
|
+
|
20
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback, no_tx_action: :warn_and_execute)
|
21
|
+
end
|
22
|
+
|
23
|
+
def after_rollback(connection: self.class.connection, &callback)
|
24
|
+
raise('expected a block') unless block_given?
|
25
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback, no_tx_action: :exception)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Effective
|
2
|
+
class AfterCommit
|
3
|
+
|
4
|
+
def initialize(connection:, **handlers)
|
5
|
+
@connection = connection
|
6
|
+
@handlers = handlers
|
7
|
+
end
|
8
|
+
|
9
|
+
def has_transactional_callbacks?
|
10
|
+
true
|
11
|
+
end
|
12
|
+
|
13
|
+
def trigger_transactional_callbacks?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def before_committed!(*)
|
18
|
+
@handlers[:before_commit]&.call
|
19
|
+
end
|
20
|
+
|
21
|
+
def committed!(args)
|
22
|
+
@handlers[:after_commit]&.call
|
23
|
+
end
|
24
|
+
|
25
|
+
def rolledback!(*)
|
26
|
+
@handlers[:after_rollback]&.call
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_to_transaction(*)
|
30
|
+
@connection.add_transaction_record(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.register_callback(connection:, name:, no_tx_action:, callback:)
|
34
|
+
raise ArgumentError, "#{name} expected a block" unless callback
|
35
|
+
|
36
|
+
unless (connection.transaction_open? && connection.current_transaction.joinable?)
|
37
|
+
case no_tx_action
|
38
|
+
when :warn_and_execute
|
39
|
+
warn "#{name}: No transaction open. Executing callback immediately."
|
40
|
+
return callback.call
|
41
|
+
when :execute
|
42
|
+
return callback.call
|
43
|
+
when :exception
|
44
|
+
raise("#{name} is useless outside transaction")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after_commit = Effective::AfterCommit.new(connection: connection, "#{name}": callback)
|
49
|
+
connection.add_transaction_record(after_commit)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -105,8 +105,10 @@ module Effective
|
|
105
105
|
attributes = (klass.new().attributes rescue nil)
|
106
106
|
return [] unless attributes
|
107
107
|
|
108
|
-
names = attributes.keys
|
109
|
-
names
|
108
|
+
names = attributes.keys
|
109
|
+
names -= belong_tos.map { |reference| reference.foreign_key }
|
110
|
+
names -= belong_tos.map { |reference| reference.foreign_type if reference.options[:polymorphic] }
|
111
|
+
names -= [klass.primary_key, 'created_at', 'updated_at'] unless all
|
110
112
|
|
111
113
|
attributes = names.inject({}) do |h, name|
|
112
114
|
if klass.respond_to?(:column_for_attribute) # Rails 4+
|
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.8.
|
4
|
+
version: 1.8.24
|
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: 2021-
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -157,11 +157,13 @@ files:
|
|
157
157
|
- app/models/concerns/acts_as_statused.rb
|
158
158
|
- app/models/concerns/acts_as_tokened.rb
|
159
159
|
- app/models/concerns/acts_as_wizard.rb
|
160
|
+
- app/models/concerns/effective_after_commit.rb
|
160
161
|
- app/models/concerns/effective_devise_user.rb
|
161
162
|
- app/models/concerns/effective_resource.rb
|
162
163
|
- app/models/concerns/has_many_rich_texts.rb
|
163
164
|
- app/models/effective/access_denied.rb
|
164
165
|
- app/models/effective/action_failed.rb
|
166
|
+
- app/models/effective/after_commit.rb
|
165
167
|
- app/models/effective/attribute.rb
|
166
168
|
- app/models/effective/code_reader.rb
|
167
169
|
- app/models/effective/http.rb
|