2018-04-11 23:17:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RepositoryActions
|
2018-04-13 17:47:33 +08:00
|
|
|
class DuplicateCell
|
2020-01-14 23:55:10 +08:00
|
|
|
def initialize(cell, new_row, user)
|
2018-04-11 23:17:19 +08:00
|
|
|
@cell = cell
|
|
|
|
@new_row = new_row
|
2018-04-16 18:38:25 +08:00
|
|
|
@user = user
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def call
|
2020-01-14 23:55:10 +08:00
|
|
|
new_value = @cell.value.dup
|
2020-01-16 23:03:13 +08:00
|
|
|
new_cell = RepositoryCell.new(repository_row: @new_row, repository_column: @cell.repository_column)
|
|
|
|
|
|
|
|
new_cell.value = new_value
|
2020-01-14 23:55:10 +08:00
|
|
|
new_value.created_by = @user
|
|
|
|
new_value.last_modified_by = @user
|
2018-04-11 23:17:19 +08:00
|
|
|
|
2020-01-14 23:55:10 +08:00
|
|
|
if respond_to?("#{@cell.value_type.split('::').last.underscore}_extra_attributes", true)
|
|
|
|
__send__("#{@cell.value_type.split('::').last.underscore}_extra_attributes", new_value)
|
|
|
|
end
|
|
|
|
new_value.save!
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
|
2020-01-14 23:55:10 +08:00
|
|
|
private
|
2018-04-11 23:17:19 +08:00
|
|
|
|
2020-01-14 23:55:10 +08:00
|
|
|
def repository_asset_value_extra_attributes(value)
|
|
|
|
new_asset = @cell.value.asset.duplicate
|
|
|
|
value.asset = new_asset
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
|
2020-01-14 23:55:10 +08:00
|
|
|
def repository_checklist_value_extra_attributes(value)
|
|
|
|
value.repository_checklist_items = @cell.value.repository_checklist_items
|
2018-04-11 23:17:19 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|