glib-web 0.4.7 → 0.4.10
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbaa7e89ae8707efe39b3f950d4e4482cd4e651a7a48184f1600c6e948aa080f
|
4
|
+
data.tar.gz: 734f9417b01c0e82d8eb2e2a96be0c778b0b6e28a042319e4a9167437b110032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f961b9bd3c3785356b4cd297340f8a3c77d5357840e34743597643f0af41bc5f6ad27376c2af80e511914da720ad15beaa697c002e93103833f38f352b91a600
|
7
|
+
data.tar.gz: c95e65b6b889457228bd60c99015cac7d134e54008c9727fd7f352a5a0fdf401396f13f26c2a93add3eafdde82bfd32eceb167b5ecd99a84cc47c09ab95022b3
|
data/app/models/glib/text.rb
CHANGED
@@ -1,6 +1,57 @@
|
|
1
1
|
module Glib
|
2
2
|
class Text < Glib::DynamicTextRecord
|
3
|
-
|
3
|
+
class << self
|
4
|
+
def dt_has_many_attached(name, dependent: :purge_later)
|
5
|
+
generated_association_methods.class_eval <<-CODE, __FILE__, __LINE__ + 1
|
6
|
+
def #{name}
|
7
|
+
@active_storage_attached_#{name} ||= ::ActiveStorage::Attached::Many.new("#{name}", self)
|
8
|
+
end
|
9
|
+
|
10
|
+
def #{name}=(attachables)
|
11
|
+
if ActiveStorage.replace_on_assign_to_many
|
12
|
+
attachment_changes["#{name}"] =
|
13
|
+
if Array(attachables).none?
|
14
|
+
::ActiveStorage::Attached::Changes::DeleteMany.new("#{name}", self)
|
15
|
+
else
|
16
|
+
::ActiveStorage::Attached::Changes::CreateMany.new("#{name}", self, attachables)
|
17
|
+
end
|
18
|
+
else
|
19
|
+
if Array(attachables).any?
|
20
|
+
attachment_changes["#{name}"] =
|
21
|
+
::ActiveStorage::Attached::Changes::CreateMany.new("#{name}", self, #{name}.blobs + attachables)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
CODE
|
26
|
+
|
27
|
+
has_many :"#{name}_attachments", -> { where(name: name) }, as: :record, class_name: "Glib::ActiveStorage::Attachment", inverse_of: :record, dependent: :destroy do
|
28
|
+
def purge
|
29
|
+
each(&:purge)
|
30
|
+
reset
|
31
|
+
end
|
32
|
+
|
33
|
+
def purge_later
|
34
|
+
each(&:purge_later)
|
35
|
+
reset
|
36
|
+
end
|
37
|
+
end
|
38
|
+
has_many :"#{name}_blobs", through: :"#{name}_attachments", class_name: "Glib::ActiveStorage::Blob", source: :blob
|
39
|
+
|
40
|
+
scope :"with_attached_#{name}", -> { includes("#{name}_attachments": :blob) }
|
41
|
+
|
42
|
+
after_save { attachment_changes[name.to_s]&.save }
|
43
|
+
|
44
|
+
after_commit(on: %i[ create update ]) { attachment_changes.delete(name.to_s).try(:upload) }
|
45
|
+
|
46
|
+
ActiveRecord::Reflection.add_attachment_reflection(
|
47
|
+
self,
|
48
|
+
name,
|
49
|
+
ActiveRecord::Reflection.create(:has_many_attached, name, nil, { dependent: dependent }, self)
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
dt_has_many_attached :images
|
4
55
|
|
5
56
|
validates :scope, presence: true
|
6
57
|
validates :lang, presence: true
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glib-web
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- app/helpers/glib/json_ui/view_builder/charts.rb
|
93
93
|
- app/helpers/glib/json_ui/view_builder/fields.rb
|
94
94
|
- app/helpers/glib/json_ui/view_builder/panels.rb
|
95
|
+
- app/models/glib/active_storage/attachment.rb
|
96
|
+
- app/models/glib/active_storage/blob.rb
|
95
97
|
- app/models/glib/dynamic_text_record.rb
|
96
98
|
- app/models/glib/text.rb
|
97
99
|
- app/policies/glib/application_policy.rb
|