effective_resources 1.8.38 → 1.9.3
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/models/effective/resource.rb +1 -1
- data/app/models/effective/resources/forms.rb +2 -0
- data/app/models/effective/resources/generator.rb +19 -0
- data/app/models/effective/resources/init.rb +6 -1
- data/app/models/effective/resources/klass.rb +40 -19
- data/app/models/effective/resources/naming.rb +0 -10
- data/app/models/effective/resources/paths.rb +1 -2
- data/app/models/effective/resources/tenants.rb +20 -0
- data/lib/effective_resources/effective_gem.rb +4 -4
- data/lib/effective_resources/version.rb +1 -1
- data/lib/effective_resources.rb +18 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 598341ec405c5f865bd47dd20eb3ac0260243a753bebc3ebe6c113364be41c20
|
4
|
+
data.tar.gz: 17fdbbf3cd41afa8342b6443c646d7082c052706e3995c4a0a0279ed8e063ae9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1b7daf92008549871a27f404f56f6c24554d49f5d8a33659fe5428af05544cc051b5824e682bce143ad459755b317d39866e2a770c916c0ca9e882d23a9349a
|
7
|
+
data.tar.gz: 4f1815a0e2f563687c78422623c20bef18143b33e01e2fa49d61681583233f8fb40884f5fba98261fb3c7b32dfb4d810f2ffab95d2f241b614ca24d50c1a6180
|
@@ -14,7 +14,7 @@ module Effective
|
|
14
14
|
include Effective::Resources::Paths
|
15
15
|
include Effective::Resources::Relation
|
16
16
|
include Effective::Resources::Sql
|
17
|
-
|
17
|
+
include Effective::Resources::Tenants
|
18
18
|
|
19
19
|
# In practice, this is initialized two ways
|
20
20
|
# With a klass and a namespace from effective_datatables
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_sting_literals: true
|
2
|
+
|
1
3
|
module Effective
|
2
4
|
module Resources
|
3
5
|
module Generator
|
@@ -26,6 +28,23 @@ module Effective
|
|
26
28
|
Array(namespaces).map { |name| name.to_s.classify }.join('::') + '::' + class_name.gsub('::', '')
|
27
29
|
end
|
28
30
|
|
31
|
+
# Tenants
|
32
|
+
def tenant_controller_path
|
33
|
+
(Tenant.module_name.downcase + '/' + controller_path) if tenant?
|
34
|
+
end
|
35
|
+
|
36
|
+
def tenant_namespaced_class_name
|
37
|
+
(Tenant.module_name + '::' + namespaced_class_name) if tenant?
|
38
|
+
end
|
39
|
+
|
40
|
+
def tenant_namespaced_module_name
|
41
|
+
(Tenant.module_name + '::' + namespaced_module_name) if tenant?
|
42
|
+
end
|
43
|
+
|
44
|
+
def tenant_class_name
|
45
|
+
(Tenant.module_name + '::' + class_name) if tenant?
|
46
|
+
end
|
47
|
+
|
29
48
|
end
|
30
49
|
end
|
31
50
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_sting_literals: true
|
2
|
+
|
1
3
|
module Effective
|
2
4
|
module Resources
|
3
5
|
module Init
|
@@ -6,7 +8,10 @@ module Effective
|
|
6
8
|
|
7
9
|
def _initialize_input(input, namespace: nil, relation: nil)
|
8
10
|
@initialized_name = input
|
9
|
-
|
11
|
+
|
12
|
+
# Sets the class but also namespaces
|
13
|
+
@model_klass = _klass_by_input(input)
|
14
|
+
@model_klass = _klass_by_input(relation) if relation.present?
|
10
15
|
|
11
16
|
# Consider controller_name
|
12
17
|
if @model_klass && input.kind_of?(String) && namespace.blank?
|
@@ -7,28 +7,11 @@ module Effective
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def datatable_klass
|
10
|
-
if defined?(EffectiveDatatables)
|
11
|
-
"#{controller_path.classify.pluralize}Datatable".safe_constantize ||
|
12
|
-
"#{controller_path.classify}Datatable".safe_constantize ||
|
13
|
-
"#{namespaced_class_name.pluralize}Datatable".safe_constantize ||
|
14
|
-
"#{namespaced_module_name.pluralize}Datatable".safe_constantize ||
|
15
|
-
"#{namespaced_class_name.pluralize.gsub('::', '')}Datatable".safe_constantize ||
|
16
|
-
"#{class_name.pluralize.camelize}Datatable".safe_constantize ||
|
17
|
-
"#{class_name.pluralize.camelize.gsub('::', '')}Datatable".safe_constantize ||
|
18
|
-
"#{name.pluralize.camelize}Datatable".safe_constantize ||
|
19
|
-
"#{name.pluralize.camelize.gsub('::', '')}Datatable".safe_constantize ||
|
20
|
-
"Effective::Datatables::#{namespaced_class_name.pluralize}".safe_constantize ||
|
21
|
-
"Effective::Datatables::#{class_name.pluralize.camelize}".safe_constantize ||
|
22
|
-
"Effective::Datatables::#{name.pluralize.camelize}".safe_constantize
|
23
|
-
end
|
10
|
+
(find_tenant_datatable_klass || find_datatable_klass) if defined?(EffectiveDatatables)
|
24
11
|
end
|
25
12
|
|
26
13
|
def controller_klass
|
27
|
-
|
28
|
-
"#{class_name.pluralize.classify}Controller".safe_constantize ||
|
29
|
-
"#{name.pluralize.classify}Controller".safe_constantize ||
|
30
|
-
"#{initialized_name.to_s.classify.pluralize}Controller".safe_constantize ||
|
31
|
-
"#{initialized_name.to_s.classify}Controller".safe_constantize
|
14
|
+
find_controller_klass
|
32
15
|
end
|
33
16
|
|
34
17
|
def active_record?
|
@@ -39,6 +22,44 @@ module Effective
|
|
39
22
|
klass && klass.ancestors.include?(ActiveModel::Model)
|
40
23
|
end
|
41
24
|
|
25
|
+
private
|
26
|
+
|
27
|
+
def find_datatable_klass
|
28
|
+
"::#{controller_path.classify.pluralize}Datatable".safe_constantize ||
|
29
|
+
"::#{controller_path.classify}Datatable".safe_constantize ||
|
30
|
+
"::#{namespaced_class_name.pluralize}Datatable".safe_constantize ||
|
31
|
+
"::#{namespaced_module_name.pluralize}Datatable".safe_constantize ||
|
32
|
+
"::#{namespaced_class_name.pluralize.gsub('::', '')}Datatable".safe_constantize ||
|
33
|
+
"::#{class_name.pluralize.camelize}Datatable".safe_constantize ||
|
34
|
+
"::#{class_name.pluralize.camelize.gsub('::', '')}Datatable".safe_constantize ||
|
35
|
+
"::#{name.pluralize.camelize}Datatable".safe_constantize ||
|
36
|
+
"::#{name.pluralize.camelize.gsub('::', '')}Datatable".safe_constantize ||
|
37
|
+
"::Effective::Datatables::#{namespaced_class_name.pluralize}".safe_constantize ||
|
38
|
+
"::Effective::Datatables::#{class_name.pluralize.camelize}".safe_constantize ||
|
39
|
+
"::Effective::Datatables::#{name.pluralize.camelize}".safe_constantize
|
40
|
+
end
|
41
|
+
|
42
|
+
def find_tenant_datatable_klass
|
43
|
+
return unless tenant?
|
44
|
+
|
45
|
+
"::#{tenant_controller_path.classify.pluralize}Datatable".safe_constantize ||
|
46
|
+
"::#{tenant_controller_path.classify}Datatable".safe_constantize ||
|
47
|
+
"::#{tenant_namespaced_class_name.pluralize}Datatable".safe_constantize ||
|
48
|
+
|
49
|
+
"::#{tenant_namespaced_module_name.pluralize}Datatable".safe_constantize ||
|
50
|
+
"::#{tenant_namespaced_class_name.pluralize.gsub('::', '')}Datatable".safe_constantize ||
|
51
|
+
"::#{tenant_class_name.pluralize.camelize}Datatable".safe_constantize ||
|
52
|
+
"::#{tenant_class_name.pluralize.camelize.gsub('::', '')}Datatable".safe_constantize
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_controller_klass
|
56
|
+
"#{namespaced_class_name.pluralize}Controller".safe_constantize ||
|
57
|
+
"#{class_name.pluralize.classify}Controller".safe_constantize ||
|
58
|
+
"#{name.pluralize.classify}Controller".safe_constantize ||
|
59
|
+
"#{initialized_name.to_s.classify.pluralize}Controller".safe_constantize ||
|
60
|
+
"#{initialized_name.to_s.classify}Controller".safe_constantize
|
61
|
+
end
|
62
|
+
|
42
63
|
end
|
43
64
|
end
|
44
65
|
end
|
@@ -65,16 +65,6 @@ module Effective
|
|
65
65
|
def human_plural_name
|
66
66
|
name.pluralize.gsub('::', ' ').underscore.gsub('_', ' ')
|
67
67
|
end
|
68
|
-
|
69
|
-
def tenant
|
70
|
-
return nil unless defined?(Tenant)
|
71
|
-
return nil unless klass.present?
|
72
|
-
return nil unless class_name.include?('::')
|
73
|
-
|
74
|
-
name = class_name.split('::').first.downcase.to_sym
|
75
|
-
name if Rails.application.config.tenants[name].present?
|
76
|
-
end
|
77
|
-
|
78
68
|
end
|
79
69
|
end
|
80
70
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Effective
|
2
|
+
module Resources
|
3
|
+
module Tenants
|
4
|
+
|
5
|
+
def tenant?
|
6
|
+
defined?(::Tenant)
|
7
|
+
end
|
8
|
+
|
9
|
+
def tenant
|
10
|
+
return unless tenant?
|
11
|
+
return nil unless klass.present?
|
12
|
+
return nil unless class_name.include?('::')
|
13
|
+
|
14
|
+
name = class_name.split('::').first.downcase.to_sym
|
15
|
+
name if Rails.application.config.tenants[name].present?
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -15,16 +15,16 @@ module EffectiveGem
|
|
15
15
|
module ClassMethods
|
16
16
|
def config(namespace = nil)
|
17
17
|
namespace ||= Tenant.current if defined?(Tenant)
|
18
|
-
@config.dig(namespace) || @config
|
18
|
+
@config.dig(namespace) || @config.dig(:effective)
|
19
19
|
end
|
20
20
|
|
21
21
|
def setup(namespace = nil, &block)
|
22
22
|
@config ||= ActiveSupport::OrderedOptions.new
|
23
|
+
|
23
24
|
namespace ||= Tenant.current if defined?(Tenant)
|
25
|
+
namespace ||= :effective
|
24
26
|
|
25
|
-
|
26
|
-
@config[namespace] ||= ActiveSupport::OrderedOptions.new
|
27
|
-
end
|
27
|
+
@config[namespace] ||= ActiveSupport::OrderedOptions.new
|
28
28
|
|
29
29
|
yield(config(namespace))
|
30
30
|
|
data/lib/effective_resources.rb
CHANGED
@@ -33,6 +33,24 @@ module EffectiveResources
|
|
33
33
|
|
34
34
|
# Utilities
|
35
35
|
|
36
|
+
# This looks up the best class give the name
|
37
|
+
# If the Tenant is present, use those classes first.
|
38
|
+
def self.best(name)
|
39
|
+
klass = if defined?(Tenant)
|
40
|
+
('::' + Tenant.module_name + '::' + name).safe_constantize ||
|
41
|
+
('::' + Tenant.module_name + '::Effective::' + name).safe_constantize
|
42
|
+
end
|
43
|
+
|
44
|
+
klass ||= begin
|
45
|
+
('::' + name).safe_constantize ||
|
46
|
+
('::Effective::' + name).safe_constantize
|
47
|
+
end
|
48
|
+
|
49
|
+
raise("unable to find best #{name}") if klass.blank?
|
50
|
+
|
51
|
+
klass
|
52
|
+
end
|
53
|
+
|
36
54
|
def self.truthy?(value)
|
37
55
|
if defined?(::ActiveRecord::ConnectionAdapters::Column::TRUE_VALUES) # Rails <5
|
38
56
|
::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.
|
4
|
+
version: 1.9.3
|
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-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- app/models/effective/resources/paths.rb
|
185
185
|
- app/models/effective/resources/relation.rb
|
186
186
|
- app/models/effective/resources/sql.rb
|
187
|
+
- app/models/effective/resources/tenants.rb
|
187
188
|
- app/views/application/_flash.html.haml
|
188
189
|
- app/views/application/create.js.erb
|
189
190
|
- app/views/application/destroy.js.erb
|