Class: Pulitzer::CloneVersion
- Inherits:
-
Object
- Object
- Pulitzer::CloneVersion
- Defined in:
- app/interactions/pulitzer/clone_version.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(version) ⇒ CloneVersion
constructor
A new instance of CloneVersion.
Constructor Details
#initialize(version) ⇒ CloneVersion
Returns a new instance of CloneVersion.
4 5 6 7 8 9 |
# File 'app/interactions/pulitzer/clone_version.rb', line 4 def initialize(version) @version = version @post = @version.post Rails.logger.info("Pulitzer::CloneVersion !!! ") Rails.logger.info($0) end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/interactions/pulitzer/clone_version.rb', line 11 def call new_version = @post.processing_version cloning_errors = [] new_version.processed_element_count = 0 @version.content_elements.each do |ce| begin cloned_content_element = ce.clone_me new_version.content_elements << cloned_content_element rescue ActiveRecord::RecordInvalid => invalid cloning_errors.push "ContentElement #{ce.id} could not be cloned: #{invalid.record.errors..join(', ')}" end new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice end @version.free_form_sections.each do |ffs| begin cloned_ffs = ffs.clone_me new_version.free_form_sections << cloned_ffs rescue ActiveRecord::RecordInvalid => invalid cloning_errors.push "Free Form Section #{ffs.id} could not be cloned: #{invalid.record.errors..join(', ')}" end new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice end @version..each do |pt| new_version. << pt.clone_me new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice end if cloning_errors.any? new_version.update(status: :processing_failed, cloning_errors: cloning_errors) else new_version.update(status: :preview) new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice end @post.new_preview_version = edit_version_path(new_version) new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice @post.broadcast_change if defined? ForeignOffice new_version end |