Sha256: 73113eaf02af927b5a72bcff3a46726d2d58d1137bd48e32641d56dff270f7eb
Contents?: true
Size: 1.42 KB
Versions: 7
Compression:
Stored size: 1.42 KB
Contents
# frozen_string_literal: true module Shimmer class FileProxy attr_reader :blob_id, :resize delegate :message_verifier, to: :class delegate :content_type, :filename, to: :blob class << self def restore(id) blob_id, resize = message_verifier.verified(id) new blob_id: blob_id, resize: resize end end def initialize(blob_id:, resize: nil, width: nil, height: nil) @blob_id = blob_id if !resize && width resize = if height "#{width}x#{height}>" else "#{width}x" end end @resize = resize end class << self def message_verifier @message_verifier ||= ApplicationRecord.signed_id_verifier end end def path Rails.application.routes.url_helpers.file_path(id, locale: nil) end def url(protocol: Rails.env.production? ? :https : :http) Rails.application.routes.url_helpers.file_url(id, locale: nil, protocol: protocol) end def blob @blob ||= ActiveStorage::Blob.find(blob_id) end def resizeable resize.present? && !blob.content_type.include?("svg") end def variant @variantvariant ||= resizeable ? blob.representation(resize: resize).processed : blob end def file @file ||= blob.service.download(variant.key) end private def id @id ||= message_verifier.generate([blob_id, resize]) end end end
Version data entries
7 entries across 7 versions & 1 rubygems