effective_resources 1.9.5 → 1.9.6
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 +4 -4
- data/app/controllers/concerns/effective/crud_controller/actions.rb +1 -1
- data/app/controllers/concerns/effective/crud_controller/save.rb +1 -1
- data/app/models/concerns/effective_after_commit.rb +3 -3
- data/app/models/effective/after_commit.rb +3 -12
- data/app/models/effective/resources/actions.rb +8 -1
- data/app/models/effective/resources/associations.rb +1 -1
- data/app/models/effective/resources/naming.rb +3 -0
- data/app/models/effective/resources/tenants.rb +4 -0
- data/lib/effective_resources/version.rb +1 -1
- data/lib/effective_resources.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e5b54802ada357459497c873ed7958745da7a62def14f6e0cea1b8b09b1ad3a
|
4
|
+
data.tar.gz: 391b11cbab23ea721aa01bb1ada824ab064b1182f16bc88083591746205424f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e33a16caedeaf449a75457ff5ee8ed7af961b3092e871ea3a404739054cb8fbf7fe0b9f388312e100ec6896c5f597591402a2efd0845a79bd4e44c1aa99fb16c
|
7
|
+
data.tar.gz: eb12d90c64e6e8467fd3dbc6733f7e7da0ee02a94231f33f464dc1896056e01f4b1a3e8998aa949815d741bb760fd732697c63682fe303cef2a132833ff801ee
|
@@ -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
|
+
EffectiveResources.transaction do
|
232
232
|
successes = resources.select do |resource|
|
233
233
|
begin
|
234
234
|
resource.public_send("#{action}!") if EffectiveResources.authorized?(self, action, resource)
|
@@ -12,17 +12,17 @@ module EffectiveAfterCommit
|
|
12
12
|
|
13
13
|
module Base
|
14
14
|
def after_commit(connection: self.class.connection, &callback)
|
15
|
-
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback
|
15
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback)
|
16
16
|
end
|
17
17
|
|
18
18
|
def before_commit(connection: self.class.connection, &callback)
|
19
19
|
raise(NotImplementedError, "#{__method__} works only with Rails 5.0+") if ActiveRecord::VERSION::MAJOR < 5
|
20
|
-
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback
|
20
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback)
|
21
21
|
end
|
22
22
|
|
23
23
|
def after_rollback(connection: self.class.connection, &callback)
|
24
24
|
raise('expected a block') unless block_given?
|
25
|
-
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback
|
25
|
+
Effective::AfterCommit.register_callback(connection: connection, name: __method__, callback: callback)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -25,20 +25,11 @@ module Effective
|
|
25
25
|
@handlers[:after_rollback]&.call
|
26
26
|
end
|
27
27
|
|
28
|
-
def self.register_callback(connection:, name:,
|
28
|
+
def self.register_callback(connection:, name:, callback:)
|
29
29
|
raise ArgumentError, "#{name} expected a block" unless callback
|
30
30
|
|
31
|
-
unless
|
32
|
-
|
33
|
-
when :warn_and_execute
|
34
|
-
warn "#{name}: No transaction open. Executing callback immediately."
|
35
|
-
return callback.call
|
36
|
-
when :execute
|
37
|
-
return callback.call
|
38
|
-
when :exception
|
39
|
-
raise("#{name} is useless outside transaction")
|
40
|
-
end
|
41
|
-
end
|
31
|
+
raise("#{name} is useless outside transaction") unless connection.transaction_open?
|
32
|
+
raise("#{name} is useless outside transaction") unless connection.current_transaction.joinable?
|
42
33
|
|
43
34
|
after_commit = Effective::AfterCommit.new("#{name}": callback)
|
44
35
|
connection.add_transaction_record(after_commit)
|
@@ -12,10 +12,17 @@ module Effective
|
|
12
12
|
@controller_path ||= route_name #[namespace, plural_name].compact * '/')
|
13
13
|
end
|
14
14
|
|
15
|
+
def engines
|
16
|
+
return ([Rails.application] + Rails::Engine.subclasses.reverse) unless tenant?
|
17
|
+
|
18
|
+
[Rails.application, Tenant.Engine] + Rails::Engine.subclasses.reverse.reject do |klass|
|
19
|
+
tenant_engines_blacklist.any? { |name| klass.name.start_with?(name) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
def routes
|
16
24
|
@routes ||= begin
|
17
25
|
routes = nil
|
18
|
-
engines = [Rails.application] + Rails::Engine.subclasses.reverse
|
19
26
|
|
20
27
|
# Check from controller_path. This is generally correct.
|
21
28
|
engines.each do |engine|
|
@@ -32,11 +32,14 @@ module Effective
|
|
32
32
|
|
33
33
|
def route_name_fallbacks
|
34
34
|
mod = class_name.split('::').first.to_s.downcase
|
35
|
+
admin = ('admin' if namespace.present? && namespace.include?('/admin'))
|
35
36
|
|
36
37
|
matches = [
|
37
38
|
route_name.singularize,
|
38
39
|
[*namespace, plural_name].join('/'),
|
40
|
+
[*admin, plural_name].join('/'),
|
39
41
|
[*namespace, name].join('/'),
|
42
|
+
[*admin, name].join('/'),
|
40
43
|
[*mod, *namespace, plural_name].join('/'),
|
41
44
|
[*mod, *namespace, name].join('/')
|
42
45
|
]
|
data/lib/effective_resources.rb
CHANGED
@@ -51,6 +51,17 @@ module EffectiveResources
|
|
51
51
|
klass
|
52
52
|
end
|
53
53
|
|
54
|
+
def self.transaction(resource = nil, &block)
|
55
|
+
connection = (resource if resource.respond_to?(:transaction))
|
56
|
+
connection ||= (resource.class if resource.class.respond_to?(:transaction))
|
57
|
+
connection ||= '::ApplicationRecord'.safe_constantize
|
58
|
+
connection ||= 'ActiveRecord::Base'.safe_constantize
|
59
|
+
|
60
|
+
raise('unable to determine transaction class') unless connection.present?
|
61
|
+
|
62
|
+
connection.transaction { yield }
|
63
|
+
end
|
64
|
+
|
54
65
|
def self.truthy?(value)
|
55
66
|
if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
|
56
67
|
::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES.include?(value)
|
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.9.
|
4
|
+
version: 1.9.6
|
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-
|
11
|
+
date: 2021-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|