Class: Pulitzer::CloneVersion
- Inherits:
-
Object
- Object
- Pulitzer::CloneVersion
- Defined in:
- app/interactions/pulitzer/clone_version.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(version, new_version = nil) ⇒ CloneVersion
constructor
A new instance of CloneVersion.
Constructor Details
#initialize(version, new_version = nil) ⇒ CloneVersion
Returns a new instance of CloneVersion.
4 5 6 7 8 9 10 |
# File 'app/interactions/pulitzer/clone_version.rb', line 4 def initialize(version, new_version = nil) @version = version @post = @version.post @new_version = new_version Rails.logger.info("Pulitzer::CloneVersion !!! ") Rails.logger.info($0) end |
Instance Method Details
#call ⇒ Object
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 53 54 55 |
# File 'app/interactions/pulitzer/clone_version.rb', line 12 def call new_version = @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 unless @new_version @post.new_preview_version = edit_version_path(new_version) end new_version.processed_element_count += 1 new_version.broadcast_change if defined? ForeignOffice @post.broadcast_change if defined? ForeignOffice new_version end |