2019-05-30 14:35:16 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ProtocolImporters
|
|
|
|
module AttachmentsBuilder
|
2019-06-27 19:10:28 +08:00
|
|
|
def self.generate(step_json, user: nil, team: nil)
|
2019-05-30 14:35:16 +08:00
|
|
|
return [] unless step_json[:attachments]&.any?
|
|
|
|
|
|
|
|
step_json[:attachments].map do |f|
|
|
|
|
Asset.new(file: URI.parse(f[:url]),
|
2019-06-27 19:10:28 +08:00
|
|
|
created_by: user,
|
|
|
|
last_modified_by: user,
|
|
|
|
team: team,
|
2019-05-30 14:35:16 +08:00
|
|
|
file_file_name: f[:name])
|
|
|
|
end
|
|
|
|
end
|
2019-06-27 19:10:28 +08:00
|
|
|
|
|
|
|
def self.generate_json(step_json)
|
|
|
|
return [] unless step_json[:attachments]&.any?
|
|
|
|
|
|
|
|
step_json[:attachments].map do |f|
|
|
|
|
{
|
|
|
|
name: f[:name],
|
|
|
|
url: f[:url]
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2019-05-30 14:35:16 +08:00
|
|
|
end
|
|
|
|
end
|