effective_resources 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31a59a4d537c8d4f363e2a5bb86758f2d0ad2b01
|
4
|
+
data.tar.gz: 9ce2460bcb27b1afe0d204f9d3528c6e92cbc6a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33394fcfcde825f6383a5d74a19ae2349ab2d94e7bcff15e9f9ac80fdaa4ae583636b5424982695d3384283eddb538f9ce02df93f06b94a72105ee532badfa59
|
7
|
+
data.tar.gz: 1efe1addab462d093e0e25f52a5d08a90299ff8a48c5402a192fa9acb5317aa5bcd49d8d360365992bc081af3037286a66bea9694b0c5ba0b2cf80a2ae15b015
|
@@ -26,7 +26,7 @@ module Effective
|
|
26
26
|
|
27
27
|
def has_ones
|
28
28
|
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
29
|
-
klass.reflect_on_all_associations(:has_one)
|
29
|
+
klass.reflect_on_all_associations(:has_one).reject { |ass| ass.class_name.to_s.start_with?('ActiveStorage::') }
|
30
30
|
end
|
31
31
|
|
32
32
|
def has_ones_ids
|
@@ -35,7 +35,7 @@ module Effective
|
|
35
35
|
|
36
36
|
def has_manys
|
37
37
|
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
38
|
-
klass.reflect_on_all_associations(:has_many).reject { |ass| ass.options[:autosave] }
|
38
|
+
klass.reflect_on_all_associations(:has_many).reject { |ass| ass.options[:autosave] || ass.class_name.to_s.start_with?('ActiveStorage::') }
|
39
39
|
end
|
40
40
|
|
41
41
|
def has_and_belongs_to_manys
|
@@ -43,6 +43,24 @@ module Effective
|
|
43
43
|
klass.reflect_on_all_associations(:has_and_belongs_to_many)
|
44
44
|
end
|
45
45
|
|
46
|
+
def active_storage_has_manys
|
47
|
+
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
48
|
+
klass.reflect_on_all_associations(:has_many).select { |ass| ass.class_name == 'ActiveStorage::Attachment' }
|
49
|
+
end
|
50
|
+
|
51
|
+
def active_storage_has_manys_ids
|
52
|
+
active_storage_has_manys.map { |ass| ass.name.to_s.gsub(/_attachments\z/, '').to_sym }
|
53
|
+
end
|
54
|
+
|
55
|
+
def active_storage_has_ones
|
56
|
+
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
57
|
+
klass.reflect_on_all_associations(:has_one).select { |ass| ass.class_name == 'ActiveStorage::Attachment' }
|
58
|
+
end
|
59
|
+
|
60
|
+
def active_storage_has_ones_ids
|
61
|
+
active_storage_has_ones.map { |ass| ass.name.to_s.gsub(/_attachment\z/, '').to_sym }
|
62
|
+
end
|
63
|
+
|
46
64
|
def nested_resources
|
47
65
|
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
48
66
|
klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] } +
|
@@ -45,6 +45,13 @@ module Effective
|
|
45
45
|
{ effective_assets: [:effective_assets] }
|
46
46
|
end
|
47
47
|
|
48
|
+
def active_storage_attributes
|
49
|
+
{}.tap do |retval|
|
50
|
+
active_storage_has_ones_ids.each { |k, v| retval[k] = [:string] }
|
51
|
+
active_storage_has_manys_ids.each { |k, v| retval[k] = [:array] }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
48
55
|
# All will include primary_key, created_at, updated_at and belongs_tos
|
49
56
|
# This is the attributes as defined by the effective_resources do .. end block
|
50
57
|
# { :name => [:string, { permitted: false }], ... }
|
@@ -58,6 +65,7 @@ module Effective
|
|
58
65
|
.merge(has_ones_attributes)
|
59
66
|
.merge(effective_addresses_attributes)
|
60
67
|
.merge(effective_assets_attributes)
|
68
|
+
.merge(active_storage_attributes)
|
61
69
|
.merge(atts)
|
62
70
|
else # This is the migrator. This should match table_attributes
|
63
71
|
belong_tos_attributes.merge(atts.reject { |_, v| v[0] == :permitted_param })
|
@@ -81,19 +89,12 @@ module Effective
|
|
81
89
|
|
82
90
|
# Used by effective_crud_controller to generate the permitted params
|
83
91
|
def permitted_attributes
|
84
|
-
# id = {klass.primary_key.to_sym => [:integer]}
|
85
|
-
# bts = belong_tos_ids.inject({}) { |h, ass| h[ass] = [:integer]; h }
|
86
|
-
# has_manys = has_manys_ids.inject({}) { |h, ass| h[ass] = [:array]; h }
|
87
|
-
# has_manys.each { |k, _| has_manys[k] = model_attributes[k] if model_attributes.key?(k) }
|
88
|
-
# Does not include nested, as they are added recursively elsewhere
|
89
|
-
# id.merge(bts).merge(model_attributes).merge(has_manys)
|
90
|
-
|
91
92
|
model_attributes(all: true)
|
92
93
|
end
|
93
94
|
|
94
95
|
# All attributes from the klass, sorted as per model attributes block.
|
95
96
|
# Does not include :id, :created_at, :updated_at unless all is passed
|
96
|
-
def klass_attributes(all: false)
|
97
|
+
def klass_attributes(all: false, sort: false)
|
97
98
|
attributes = (klass.new().attributes rescue nil)
|
98
99
|
return [] unless attributes
|
99
100
|
|
@@ -108,7 +109,7 @@ module Effective
|
|
108
109
|
end; h
|
109
110
|
end
|
110
111
|
|
111
|
-
sort_by_model_attributes(attributes)
|
112
|
+
sort ? sort_by_model_attributes(attributes) : attributes
|
112
113
|
end
|
113
114
|
|
114
115
|
private
|
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.1.
|
4
|
+
version: 1.1.1
|
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: 2018-12-
|
11
|
+
date: 2018-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|