Class: Pulitzer::PartialsController::UpgradePartialVersion
- Inherits:
-
Object
- Object
- Pulitzer::PartialsController::UpgradePartialVersion
- Defined in:
- app/interactions/pulitzer/partials_controller/upgrade_partial_version.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(partial) ⇒ UpgradePartialVersion
constructor
A new instance of UpgradePartialVersion.
Constructor Details
#initialize(partial) ⇒ UpgradePartialVersion
Returns a new instance of UpgradePartialVersion.
3 4 5 6 |
# File 'app/interactions/pulitzer/partials_controller/upgrade_partial_version.rb', line 3 def initialize(partial) @partial = partial @free_form_section = partial.free_form_section end |
Instance Method Details
#call ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/interactions/pulitzer/partials_controller/upgrade_partial_version.rb', line 8 def call most_recent_partial_version = @partial.post_type_version.post_type.most_recent_published_post_type_version new_partial = @free_form_section.partials.create(label: @partial.label, post_type_version_id: most_recent_partial_version.id, sort_order: @partial.sort_order) Pulitzer::CreatePartialContentElements.new(new_partial).call content_elements = new_partial.reload.content_elements.to_a content_elements.each_with_index do |ce, index| old_ce = @partial.content_elements.find_by(label: ce.label) if old_ce cloned = old_ce.clone_me new_partial.content_elements << cloned cloned.update(post_type_content_element_type_id: ce.post_type_content_element_type_id, partial_id: ce.partial_id, version_id: ce.version_id, sort_order: index) ce.destroy! end end @partial.destroy! new_partial.reload end |