Class: Decidim::Cdtb::ParticipatorySpaces::MoveImagesToContentBlock
- Includes:
- ManagesContentBlocks
- Defined in:
- lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb
Overview
Move images to content block for participatory spaces
Instance Attribute Summary collapse
-
#num_added ⇒ Object
readonly
Returns the value of attribute num_added.
Attributes inherited from Task
Instance Method Summary collapse
- #do_execution(context) ⇒ Object
- #end_execution(_ctx) ⇒ Object
-
#initialize(processed_models) ⇒ MoveImagesToContentBlock
constructor
A new instance of MoveImagesToContentBlock.
- #prepare_execution(_ctx = nil) ⇒ Object
- #total_items ⇒ Object
Methods included from ManagesContentBlocks
#current_space_content_blocks, #find_or_create_content_block, #manifest_for, #scope_name, #update_content_block_image
Methods inherited from Task
Methods included from TasksUtils
#do_log_error, #do_log_info, #log_task_end, #log_task_failure, #log_task_info, #log_task_step, #log_task_title, #logger
Constructor Details
#initialize(processed_models) ⇒ MoveImagesToContentBlock
Returns a new instance of MoveImagesToContentBlock.
12 13 14 15 16 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 12 def initialize(processed_models) = { title: self.class.name } @processed_models = processed_models super("MOVING IMAGES...", progress_bar:) end |
Instance Attribute Details
#num_added ⇒ Object (readonly)
Returns the value of attribute num_added.
18 19 20 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 18 def num_added @num_added end |
Instance Method Details
#do_execution(context) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 33 def do_execution(context) = context[:progress_bar] @processed_models.each do |processed_model| log_task_step("Processing #{processed_model}") spaces = processed_model spaces.find_each do |space| image_content_block = find_or_create_content_block(space, "hero") next if image_content_block.images.present? update_content_block_image(image_content_block, space.) @num_added += 1 .increment end end end |
#end_execution(_ctx) ⇒ Object
54 55 56 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 54 def end_execution(_ctx) log_task_step("#{@num_added} content blocks added") end |
#prepare_execution(_ctx = nil) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 20 def prepare_execution(_ctx = nil) @num_added= @num_items= 0 @processed_models.each do |model_name| @num_items+= model_name.count end log_task_info("Moving images to content block in #{@num_items} spaces...") end |
#total_items ⇒ Object
29 30 31 |
# File 'lib/decidim/cdtb/participatory_spaces/move_images_to_content_block.rb', line 29 def total_items @num_items end |