para 0.11.2 → 0.11.4

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: 6f6fa00155104b2a8b6557c6ec04c3c64ae456eaeea26605757f0b4fef347fcc
4
- data.tar.gz: 91243a2554514c1acbffec0d730276ffe5db4063b21723b91f0ed842b9ccb228
3
+ metadata.gz: 7e85115947c19d8b42e046fca2d3f6c6fbc4de0c6ec23d7941936508a6b5ef67
4
+ data.tar.gz: 400dce7d9cc881e1fd4a94efa11eba4f71f8bcc3cb169acb0f5e1a476bc42bd9
5
5
  SHA512:
6
- metadata.gz: 6842f6aa0f5ed769519fe0ce471ea9cb5bde60458974debc956ba094f93eb799dfbb4d0f9d6a0728e2131c3376088ecf7cd904130a228345b9d204664fdf8a7b
7
- data.tar.gz: 9de0c468a9e29066ca22a2cd0f2d5f600c0d4d7397b63034ab8a9a53784aa255901f1ea95e3f9759103a2a411d3f163c3a3bdb763b6e02e1c76008f90e29c2d3
6
+ metadata.gz: 2f83c8f52b7c04547afc074473d5f75ee3c7c1a4acd0b8b32725f0ae5985fca258a3a5a21399763b90c117ecc283d8241ffb15a1271666aa33f850a47044348f
7
+ data.tar.gz: 8d45c55a0805a8965bb5ea8eae588f7ca43b2f2318ebf0cbb195dffae962f6e15f68bbeb54bb2e40c78c70758bbf4b6783861f873e79270f33fb5320a0db4a29
@@ -1,9 +1,15 @@
1
- .add-button.nested-many-inset-add-button.dropdown
2
- %button.btn.btn-shadow.dropdown-toggle{ class: add_button_class, type: 'button', data: { toggle: 'dropdown' } }
1
+ - if subclasses.one?
2
+ - submodel = subclasses.first
3
+
4
+ = link_to_add_association form, attribute_name, wrap_object: proc { with_inverse_association_for(submodel.new, attribute_name, form.object) }, partial: find_partial_for(model, 'nested_many/container', partial_dir: 'inputs'), form_name: 'form', class: "btn btn-shadow add-button nested-many-inset-add-button #{add_button_class}", data: { :'association-insertion-node' => "##{ dom_identifier }", :'association-insertion-method' => 'append' }, render_options: { nested_attribute_name: attribute_name, orderable: orderable, locals: { model: submodel, nested_locals: nested_locals, inset: inset, uncollapsed: uncollapsed, render_partial: render_partial, remote_partial_params: remote_partial_params } } do
3
5
  = add_button_label
4
- %i.fa.fa-angle-down
5
- %ul.dropdown-menu
6
- - subclasses.each do |submodel|
7
- %li
8
- = link_to_add_association form, attribute_name, wrap_object: proc { with_inverse_association_for(submodel.new, attribute_name, form.object) }, partial: find_partial_for(submodel, 'nested_many/container', partial_dir: 'inputs'), form_name: 'form', class: 'dropdown-link', data: { :'association-insertion-node' => "##{ dom_identifier }", :'association-insertion-method' => 'append' }, render_options: { nested_attribute_name: attribute_name, orderable: orderable, locals: { model: submodel, nested_locals: nested_locals, inset: inset, uncollapsed: uncollapsed, render_partial: render_partial, remote_partial_params: remote_partial_params } } do
9
- = submodel.model_name.human
6
+ - else
7
+ .add-button.nested-many-inset-add-button.dropdown
8
+ %button.btn.btn-shadow.dropdown-toggle{ class: add_button_class, type: 'button', data: { toggle: 'dropdown' } }
9
+ = add_button_label
10
+ %i.fa.fa-angle-down
11
+ %ul.dropdown-menu
12
+ - subclasses.each do |submodel|
13
+ %li
14
+ = link_to_add_association form, attribute_name, wrap_object: proc { with_inverse_association_for(submodel.new, attribute_name, form.object) }, partial: find_partial_for(submodel, 'nested_many/container', partial_dir: 'inputs'), form_name: 'form', class: 'dropdown-link', data: { :'association-insertion-node' => "##{ dom_identifier }", :'association-insertion-method' => 'append' }, render_options: { nested_attribute_name: attribute_name, orderable: orderable, locals: { model: submodel, nested_locals: nested_locals, inset: inset, uncollapsed: uncollapsed, render_partial: render_partial, remote_partial_params: remote_partial_params } } do
15
+ = submodel.model_name.human
@@ -17,7 +17,7 @@ module Para
17
17
 
18
18
  attachment_reflections = original.class.reflections.select do |name, reflection|
19
19
  name.to_s.match(ATTACHMENTS_RELATION_REGEX) &&
20
- reflection.options[:class_name] == "ActiveStorage::Attachment"
20
+ reflection.options[:class_name] == 'ActiveStorage::Attachment'
21
21
  end
22
22
 
23
23
  attachment_reflections.each do |name, reflection|
@@ -26,16 +26,27 @@ module Para
26
26
 
27
27
  if reflection.collection?
28
28
  association_target.each do |attachment|
29
- clone_attachment(name, attachment)
29
+ clone_attachment_if_needed(name, attachment)
30
30
  end
31
31
  else
32
- clone_attachment(name, association_target)
32
+ clone_attachment_if_needed(name, association_target)
33
33
  end
34
34
  end
35
35
  end
36
36
 
37
+ def clone_attachment_if_needed(name, attachment)
38
+ return if attachment.nil?
39
+
40
+ store_key = store_key_for(attachment)
41
+
42
+ # If the attachment has already been cloned, we don't need to clone it again
43
+ return if dictionary[store_key]&.key?(attachment)
44
+
45
+ clone_attachment(name, attachment)
46
+ end
47
+
37
48
  def clone_attachment(name, original_attachment)
38
- association_name = name.gsub(ATTACHMENTS_RELATION_REGEX, "")
49
+ association_name = name.gsub(ATTACHMENTS_RELATION_REGEX, '')
39
50
  original_blob = original_attachment.blob
40
51
 
41
52
  # Handle missing file in storage service by bypassing the attachment cloning
@@ -45,7 +56,7 @@ module Para
45
56
  attachment_target = clone.send(association_name)
46
57
 
47
58
  cloned_blob = ActiveStorage::Blob.create_and_upload!(
48
- io: tempfile,
59
+ io: tempfile,
49
60
  filename: original_blob.filename,
50
61
  content_type: original_blob.content_type
51
62
  )
@@ -67,10 +78,10 @@ module Para
67
78
  # doesn't always return the same, so for now we still handle the Rails 5.2 case.
68
79
  def find_cloned_attachment(attachment_target, original_blob)
69
80
  attachments = if attachment_target.attachments.any?
70
- attachment_target.attachments
71
- else
72
- [attachment_target.attachment]
73
- end
81
+ attachment_target.attachments
82
+ else
83
+ [attachment_target.attachment]
84
+ end
74
85
 
75
86
  attachment = attachments.find do |att|
76
87
  att.blob.checksum == original_blob.checksum
@@ -81,11 +92,15 @@ module Para
81
92
  # simulates what the deep_cloneable gem does when it clones a resource
82
93
  #
83
94
  def store_cloned(source, clone)
84
- store_key = source.class.name.tableize.to_sym
95
+ store_key = store_key_for(source)
85
96
 
86
97
  dictionary[store_key] ||= {}
87
98
  dictionary[store_key][source] = clone
88
99
  end
100
+
101
+ def store_key_for(attachment)
102
+ attachment.class.name.tableize.to_sym
103
+ end
89
104
  end
90
105
  end
91
106
  end
data/lib/para/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Para
4
- VERSION = '0.11.2'
4
+ VERSION = '0.11.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.2
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-24 00:00:00.000000000 Z
11
+ date: 2023-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_decorator
@@ -862,7 +862,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
862
862
  - !ruby/object:Gem::Version
863
863
  version: '0'
864
864
  requirements: []
865
- rubygems_version: 3.4.4
865
+ rubygems_version: 3.4.8
866
866
  signing_key:
867
867
  specification_version: 4
868
868
  summary: Rails admin engine