Class: Pulitzer::UpdateFreeFormSectionPartials

Inherits:
Object
  • Object
show all
Defined in:
app/interactions/pulitzer/update_free_form_section_partials.rb

Instance Method Summary collapse

Constructor Details

#initialize(partial_type, old_label) ⇒ UpdateFreeFormSectionPartials

Returns a new instance of UpdateFreeFormSectionPartials.



3
4
5
# File 'app/interactions/pulitzer/update_free_form_section_partials.rb', line 3

def initialize(partial_type, old_label)
  @partial_type, @old_label = partial_type, old_label
end

Instance Method Details

#callObject



7
8
9
10
11
12
13
14
15
16
17
# File 'app/interactions/pulitzer/update_free_form_section_partials.rb', line 7

def call
  free_form_section_type  = @partial_type.free_form_section_type
  post_type               = free_form_section_type.post_type
  post_type.posts.each do |post|
    if post.preview_version
      free_form_section = post.preview_version.free_form_sections.find_by(name: free_form_section_type.name)
      partial = free_form_section.partials.find_by(label: @old_label)
      partial.update(label: @partial_type.label, layout_id: @partial_type.layout_id) if partial
    end
  end
end