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: b310f37fb4b17ad903b9747af586ced2918eb3bd2415dafc68ebf7133415ca40
4
- data.tar.gz: 6fca728dab6fffa7ced37f979f5d0537d42bbee83410ce7db54a26d10441f482
3
+ metadata.gz: dbaa7e89ae8707efe39b3f950d4e4482cd4e651a7a48184f1600c6e948aa080f
4
+ data.tar.gz: 734f9417b01c0e82d8eb2e2a96be0c778b0b6e28a042319e4a9167437b110032
5
5
  SHA512:
6
- metadata.gz: 6f1b8b84319689a92c56827bd4791be5da1fe048f627b88a3e60c1d5d8a47adac19ac2e7b6d6ea0985ed8c0bdff4426893c88780aa548eecac29d907138d757b
7
- data.tar.gz: 02a7d64bd89e2a49073b6d9d66e7b145c36f750d05f143ed5c6b476dcedba5af1e55d6c60115e26a06dea7ac50d7bd14d10f1976cd746b4d14e5365780705664
6
+ metadata.gz: f961b9bd3c3785356b4cd297340f8a3c77d5357840e34743597643f0af41bc5f6ad27376c2af80e511914da720ad15beaa697c002e93103833f38f352b91a600
7
+ data.tar.gz: c95e65b6b889457228bd60c99015cac7d134e54008c9727fd7f352a5a0fdf401396f13f26c2a93add3eafdde82bfd32eceb167b5ecd99a84cc47c09ab95022b3
@@ -0,0 +1,9 @@
1
+ module Glib
2
+ module ActiveStorage
3
+ class Attachment < ::ActiveStorage::Attachment
4
+ if respond_to? :connects_to
5
+ connects_to database: { writing: :dynamic_text, reading: :dynamic_text }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Glib
2
+ module ActiveStorage
3
+ class Blob < ::ActiveStorage::Blob
4
+ if respond_to? :connects_to
5
+ connects_to database: { writing: :dynamic_text, reading: :dynamic_text }
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,6 +1,57 @@
1
1
  module Glib
2
2
  class Text < Glib::DynamicTextRecord
3
- has_many_attached :images
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.7
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