diff --git a/app/models/communication/block/abstract.rb b/app/models/communication/block/abstract.rb index 8e78e8dfec8d636c5b452d4eb92d3120f45efc36..27d7e6f47790b92ba1480cdc04a11dcefacd83d5 100644 --- a/app/models/communication/block/abstract.rb +++ b/app/models/communication/block/abstract.rb @@ -6,11 +6,27 @@ class Communication::Block::Abstract end def git_dependencies - [] + unless @git_dependencies + @git_dependencies = [] + build_git_dependencies + @git_dependencies.uniq! + end + @git_dependencies end protected + def build_git_dependencies + end + + def add_dependency(dependency) + if dependency.is_a? Array + @git_dependencies += dependency + else + @git_dependencies += [dependency] + end + end + def find_blob(object, key) id = object.dig(key, 'id') return if id.blank? diff --git a/app/models/communication/block/gallery.rb b/app/models/communication/block/gallery.rb index f43d7ee2f2db615a6bf45097b0e256276cd5d230..be03ef820a22d1c1983469662762b7880a481f8a 100644 --- a/app/models/communication/block/gallery.rb +++ b/app/models/communication/block/gallery.rb @@ -1,12 +1,9 @@ class Communication::Block::Gallery < Communication::Block::Abstract - def git_dependencies + def build_git_dependencies dependencies = [] elements.each do |image| - id = image.dig('file', 'id') - next if id.blank? - blob = university.active_storage_blobs.find id - next if blob.nil? - dependencies += [blob] + blob = find_blob image, 'file' + add_dependency blob unless blob.nil? end dependencies.uniq end diff --git a/app/models/communication/block/organization_chart.rb b/app/models/communication/block/organization_chart.rb index 78c76ca6133256433fd9799a8b4c76011eab0b27..9e5859b2cdaca962084fbad76051ab2eb6889efd 100644 --- a/app/models/communication/block/organization_chart.rb +++ b/app/models/communication/block/organization_chart.rb @@ -1,14 +1,12 @@ class Communication::Block::OrganizationChart < Communication::Block::Abstract - def git_dependencies - dependencies = [] + def build_git_dependencies elements.each do |person| id = person['id'] next if id.blank? person = university.people.find id next if person.nil? - dependencies += [person] - dependencies += person.active_storage_blobs + add_dependency person + add_dependency person.active_storage_blobs end - dependencies.uniq end end diff --git a/app/models/communication/block/partner.rb b/app/models/communication/block/partner.rb index 539a41f47686a5952992109bceaa5c9119249bcf..c54cfbe067336ca7edf53727ceb3ac778f85f19b 100644 --- a/app/models/communication/block/partner.rb +++ b/app/models/communication/block/partner.rb @@ -1,13 +1,8 @@ class Communication::Block::Partner < Communication::Block::Abstract - def git_dependencies - dependencies = [] + def build_git_dependencies elements.each do |partner| - id = partner.dig('logo', 'id') - next if id.blank? - blob = university.active_storage_blobs.find id - next if blob.nil? - dependencies += [blob] + blob = find_blob partner, 'logo' + add_dependency blob unless blob.nil? end - dependencies.uniq end end diff --git a/app/models/communication/block/testimonial.rb b/app/models/communication/block/testimonial.rb index 7b1ce22be164eddb3c7792276c545a2d2882489d..797d11954b3cf5a3d53de53ffa91ee2ce972ff67 100644 --- a/app/models/communication/block/testimonial.rb +++ b/app/models/communication/block/testimonial.rb @@ -1,11 +1,8 @@ class Communication::Block::Testimonial < Communication::Block::Abstract - def git_dependencies - dependencies = [] + def build_git_dependencies elements.each do |testimonial| blob = find_blob testimonial, 'photo' - next if blob.nil? - dependencies += [blob] + add_dependency blob unless blob.nil? end - dependencies.uniq end end