working on image feature
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
require "base64"
|
||||
|
||||
class BackupExport
|
||||
FORMAT = "car_tracker_backup".freeze
|
||||
VERSION = 1
|
||||
VERSION = 2
|
||||
|
||||
def self.call
|
||||
new.call
|
||||
def self.call(include_images: false)
|
||||
new(include_images: include_images).call
|
||||
end
|
||||
|
||||
def initialize(include_images: false)
|
||||
@include_images = include_images
|
||||
end
|
||||
|
||||
def call
|
||||
@@ -17,6 +23,8 @@ class BackupExport
|
||||
|
||||
private
|
||||
|
||||
attr_reader :include_images
|
||||
|
||||
def vehicles
|
||||
Vehicle.includes(
|
||||
:maintenance_schedules,
|
||||
@@ -67,7 +75,7 @@ class BackupExport
|
||||
"gallons_pumped" => decimal_string(entry.gallons_pumped),
|
||||
"price_paid" => decimal_string(entry.price_paid),
|
||||
"updated_by_user" => user_data(entry.updated_by_user)
|
||||
}
|
||||
}.tap { |data| data["images"] = images(entry) if include_images }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -80,6 +88,18 @@ class BackupExport
|
||||
"odometer" => entry.odometer,
|
||||
"cost" => decimal_string(entry.cost),
|
||||
"updated_by_user" => user_data(entry.updated_by_user)
|
||||
}.tap { |data| data["images"] = images(entry) if include_images }
|
||||
end
|
||||
end
|
||||
|
||||
def images(entry)
|
||||
entry.images.map do |image|
|
||||
{
|
||||
"filename" => image.filename.to_s,
|
||||
"content_type" => image.content_type,
|
||||
"checksum" => image.checksum,
|
||||
"byte_size" => image.byte_size,
|
||||
"data_base64" => Base64.strict_encode64(image.download)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user