Class: Imgproxy::UrlAdapters::ActiveStorageGCS

Inherits:
ActiveStorage show all
Defined in:
lib/imgproxy/url_adapters/active_storage_gcs.rb

Overview

Adapter for ActiveStorage with S3 service

Imgproxy.configure do |config|
  config.url_adapters.add Imgproxy::UrlAdapters::ActiveStorageGCS.new("bucket_name")
end

Imgproxy.url_for(user.avatar)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name) ⇒ ActiveStorageGCS

Returns a new instance of ActiveStorageGCS.

Parameters:

  • bucket_name (String)

    Google Cloud Storage bucket name



14
15
16
# File 'lib/imgproxy/url_adapters/active_storage_gcs.rb', line 14

def initialize(bucket_name)
  @bucket_name = bucket_name
end

Instance Attribute Details

#bucket_nameString (readonly)

Returns Google Cloud Storage bucket name.

Returns:

  • (String)

    Google Cloud Storage bucket name



19
20
21
# File 'lib/imgproxy/url_adapters/active_storage_gcs.rb', line 19

def bucket_name
  @bucket_name
end

Instance Method Details

#applicable?(image) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/imgproxy/url_adapters/active_storage_gcs.rb', line 21

def applicable?(image)
  super &&
    image.service.is_a?(::ActiveStorage::Service::GCSService)
end

#url(image) ⇒ Object



26
27
28
# File 'lib/imgproxy/url_adapters/active_storage_gcs.rb', line 26

def url(image)
  "gs://#{bucket_name}/#{image.key}"
end