effective_resources 1.9.3 → 1.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/concerns/effective/crud_controller/actions.rb +3 -3
- data/app/controllers/concerns/effective/crud_controller/dsl.rb +14 -2
- data/app/controllers/concerns/effective/crud_controller/save.rb +1 -1
- data/app/controllers/concerns/effective/crud_controller.rb +8 -7
- data/app/models/concerns/acts_as_wizard.rb +14 -3
- 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/init.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: 1054a07a0d8e4b48dd20bdf6c6f0acd310e67b943cbeb001b6414538fd723397
|
4
|
+
data.tar.gz: 5b042ad47a6827741163a6fffd9c38c2b9b67b175acc8d7927153e08055a16aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b972f9e99251ef240776847b2235c8359be6c7208a1854caa52f72ab87bf0e7b8cfd269db1f27b7893d75ca8eeb489c20990c9bce567cd9fe8e4e23c4d9f8d7c
|
7
|
+
data.tar.gz: d455d59e0bcfd461b613b46710bfa44acb452171a960bb1d5444d009ccb93c95c105dcc66bd925ee8745971bfeb0d96635f774258f121cad3ecf2aab0adcdc40
|
@@ -9,7 +9,7 @@ module Effective
|
|
9
9
|
@page_title ||= resource_plural_name.titleize
|
10
10
|
|
11
11
|
self.resources ||= resource_scope.all if resource_scope.respond_to?(:all)
|
12
|
-
@datatable = resource_datatable(
|
12
|
+
@datatable = resource_datatable()
|
13
13
|
|
14
14
|
run_callbacks(:resource_render)
|
15
15
|
end
|
@@ -214,7 +214,7 @@ module Effective
|
|
214
214
|
@page_title ||= "#{action.to_s.titleize} #{resource_plural_name.titleize}"
|
215
215
|
|
216
216
|
if request.get?
|
217
|
-
@datatable = resource_datatable(
|
217
|
+
@datatable = resource_datatable()
|
218
218
|
run_callbacks(:resource_render)
|
219
219
|
|
220
220
|
view = lookup_context.template_exists?(action, _prefixes) ? action : :index
|
@@ -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)
|
@@ -61,7 +61,20 @@ module Effective
|
|
61
61
|
raise 'expected a label or block' unless (label || block_given?)
|
62
62
|
|
63
63
|
instance_exec do
|
64
|
-
before_action(opts)
|
64
|
+
before_action(opts) do
|
65
|
+
@page_title ||= (block_given? ? instance_exec(&block) : label).to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# datatable -> { MyDatatable.new }, only: [:index]
|
71
|
+
def datatable(obj = nil, opts = {}, &block)
|
72
|
+
raise 'expected a proc or block' unless (obj.respond_to?(:call) || block_given?)
|
73
|
+
|
74
|
+
instance_exec do
|
75
|
+
before_action(opts) do
|
76
|
+
@datatable ||= (block_given? ? instance_exec(&block) : obj.call)
|
77
|
+
end
|
65
78
|
end
|
66
79
|
end
|
67
80
|
|
@@ -84,7 +97,6 @@ module Effective
|
|
84
97
|
else
|
85
98
|
define_method(:resource_scope_relation) { return obj }
|
86
99
|
end
|
87
|
-
|
88
100
|
end
|
89
101
|
|
90
102
|
end
|
@@ -108,15 +108,16 @@ module Effective
|
|
108
108
|
resource_scope.where_values_hash.symbolize_keys
|
109
109
|
end
|
110
110
|
|
111
|
-
def resource_datatable
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
111
|
+
def resource_datatable
|
112
|
+
# This might have been done from a before action or dsl method
|
113
|
+
unless @datatable.nil?
|
114
|
+
raise('expected @datatable to be an Effective::Datatable') unless @datatable.kind_of?(Effective::Datatable)
|
115
|
+
|
116
|
+
@datatable.effective_resource = effective_resource
|
117
|
+
return @datatable
|
118
118
|
end
|
119
119
|
|
120
|
+
datatable_klass = effective_resource.datatable_klass
|
120
121
|
return unless datatable_klass.present?
|
121
122
|
|
122
123
|
datatable = datatable_klass.new(resource_datatable_attributes)
|
@@ -76,7 +76,11 @@ module ActsAsWizard
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def next_step
|
79
|
-
|
79
|
+
first_uncompleted_step ||
|
80
|
+
last_completed_step ||
|
81
|
+
required_steps.reverse.find { |step| can_visit_step?(step) } ||
|
82
|
+
required_steps.first ||
|
83
|
+
:start
|
80
84
|
end
|
81
85
|
|
82
86
|
def previous_step(step)
|
@@ -89,6 +93,13 @@ module ActsAsWizard
|
|
89
93
|
previous.blank? || has_completed_step?(previous)
|
90
94
|
end
|
91
95
|
|
96
|
+
def has_completed_all_previous_steps?(step)
|
97
|
+
index = required_steps.index(step).to_i
|
98
|
+
previous = required_steps[0...index]
|
99
|
+
|
100
|
+
previous.blank? || previous.all? { |step| has_completed_step?(step) }
|
101
|
+
end
|
102
|
+
|
92
103
|
def has_completed_last_step?
|
93
104
|
has_completed_step?(required_steps.last)
|
94
105
|
end
|
@@ -97,12 +108,12 @@ module ActsAsWizard
|
|
97
108
|
|
98
109
|
def can_revisit_completed_steps(step)
|
99
110
|
return (step == required_steps.last) if has_completed_last_step?
|
100
|
-
|
111
|
+
has_completed_all_previous_steps?(step)
|
101
112
|
end
|
102
113
|
|
103
114
|
def cannot_revisit_completed_steps(step)
|
104
115
|
return (step == required_steps.last) if has_completed_last_step?
|
105
|
-
|
116
|
+
has_completed_all_previous_steps?(step) && !has_completed_step?(step)
|
106
117
|
end
|
107
118
|
|
108
119
|
end
|
@@ -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|
|
@@ -11,7 +11,7 @@ module Effective
|
|
11
11
|
|
12
12
|
# Sets the class but also namespaces
|
13
13
|
@model_klass = _klass_by_input(input)
|
14
|
-
@model_klass = _klass_by_input(relation)
|
14
|
+
@model_klass = _klass_by_input(relation) unless relation.nil?
|
15
15
|
|
16
16
|
# Consider controller_name
|
17
17
|
if @model_klass && input.kind_of?(String) && namespace.blank?
|
@@ -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.7
|
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
|