effective_resources 1.9.5 → 1.9.9
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/acts_as_statused.rb +4 -5
- 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 +12 -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 +26 -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: 144152b4742a10b3d574bbe0458c8f80db4490dd178d0dbe323a180a05a87b46
|
4
|
+
data.tar.gz: 533c8ef7927b1782d85efaea9affc6c2a16d56452ae3c8d0df45f1ec8535f795
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cdd68a72ad36d7745ea3178d9f9b640799e1c406f0f1dec2d2e7c376dccadc02724c7298c10a96198dc552c9de21591457b36c601b74a91b60222675d8569386
|
7
|
+
data.tar.gz: 1d126ded3ea4f19d8d4d2040bf32037eb7a0e0c3f7adbdc2e9514d31fa35f54f301bdf6bafb27c3b1e7757ba680577440b2c6a7110f2103d94a07c98f702518b
|
@@ -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)
|
@@ -125,16 +125,16 @@ module ActsAsStatused
|
|
125
125
|
define_method("#{sym}?") { status == sym.to_s }
|
126
126
|
define_method("was_#{sym}?") { send("#{sym}_at").present? }
|
127
127
|
|
128
|
-
unless has_attribute?("#{sym}_at")
|
128
|
+
#unless has_attribute?("#{sym}_at")
|
129
129
|
define_method("#{sym}_at") { status_steps["#{sym}_at".to_sym] }
|
130
130
|
define_method("#{sym}_at=") { |value| status_steps["#{sym}_at".to_sym] = value }
|
131
|
-
end
|
131
|
+
#end
|
132
132
|
|
133
|
-
unless has_attribute?("#{sym}_by_id")
|
133
|
+
#unless has_attribute?("#{sym}_by_id")
|
134
134
|
define_method("#{sym}_by") { acts_as_statused_by_user(sym) }
|
135
135
|
define_method("#{sym}_by_id") { status_steps["#{sym}_by".to_sym] }
|
136
136
|
define_method("#{sym}_by_id=") { |value| status_steps["#{sym}_by".to_sym] = value }
|
137
|
-
end
|
137
|
+
#end
|
138
138
|
|
139
139
|
# approved!
|
140
140
|
define_method("#{sym}!") do |atts = {}|
|
@@ -180,4 +180,3 @@ module ActsAsStatused
|
|
180
180
|
end
|
181
181
|
|
182
182
|
end
|
183
|
-
|
@@ -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,21 @@ module Effective
|
|
12
12
|
@controller_path ||= route_name #[namespace, plural_name].compact * '/')
|
13
13
|
end
|
14
14
|
|
15
|
+
def route_engines
|
16
|
+
if tenant? && Tenant.current.present?
|
17
|
+
[Rails.application, Tenant.Engine] + Rails::Engine.subclasses.reverse.reject do |klass|
|
18
|
+
tenant_engines_blacklist.any? { |name| klass.name.start_with?(name) }
|
19
|
+
end
|
20
|
+
else
|
21
|
+
[Rails.application] + Rails::Engine.subclasses.reverse
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
def routes
|
16
26
|
@routes ||= begin
|
17
27
|
routes = nil
|
18
|
-
|
28
|
+
|
29
|
+
engines = route_engines()
|
19
30
|
|
20
31
|
# Check from controller_path. This is generally correct.
|
21
32
|
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,32 @@ 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
|
+
|
65
|
+
# Used by streaming CSV export in datatables
|
66
|
+
def self.with_resource_enumerator(&block)
|
67
|
+
raise('expected a block') unless block_given?
|
68
|
+
|
69
|
+
tenant = Tenant.current if defined?(Tenant)
|
70
|
+
|
71
|
+
if tenant
|
72
|
+
Enumerator.new do |enumerator|
|
73
|
+
Tenant.as(tenant) { yield(enumerator) }
|
74
|
+
end
|
75
|
+
else
|
76
|
+
Enumerator.new { |enumerator| yield(enumerator) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
54
80
|
def self.truthy?(value)
|
55
81
|
if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
|
56
82
|
::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.9
|
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-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|