Class: Imgproxy::UrlAdapters::ActiveStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/imgproxy/url_adapters/active_storage.rb

Overview

Adapter for ActiveStorage

Imgproxy.configure do |config|
  config.url_adapters.add Imgproxy::UrlAdapters::ActiveStorage.new
end

Imgproxy.url_for(user.avatar)

Instance Method Summary collapse

Instance Method Details

#applicable?(image) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/imgproxy/url_adapters/active_storage.rb', line 13

def applicable?(image)
  image.is_a?(::ActiveStorage::Attached::One) ||
    image.is_a?(::ActiveStorage::Attachment) ||
    image.is_a?(::ActiveStorage::Blob)
end

#url(image) ⇒ Object



19
20
21
22
23
24
# File 'lib/imgproxy/url_adapters/active_storage.rb', line 19

def url(image)
  return s3_url(image) if use_s3_url(image)
  return gcs_url(image) if use_gcs_url(image)

  Rails.application.routes.url_helpers.url_for(image)
end