class Imgproxy::UrlAdapters

URL adapters config. Allows to use this gem with ActiveStorage, Shrine, etc.

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

Imgproxy.url_for(user.avatar)

Attributes

adapters[R]

@return [Array] Currently added adapters

Public Class Methods

new() click to toggle source
# File lib/imgproxy/url_adapters.rb, line 19
def initialize
  @adapters = []
end

Public Instance Methods

add(adapter) click to toggle source

Add adapter to the end of the list @return [Array]

# File lib/imgproxy/url_adapters.rb, line 25
def add(adapter)
  adapters << adapter
end
clear!() click to toggle source

Remove all adapters from the list @return [Array]

# File lib/imgproxy/url_adapters.rb, line 37
def clear!
  @adapters = []
end
prepend() click to toggle source

Add adapter to the beginning of the list @return [Array]

# File lib/imgproxy/url_adapters.rb, line 31
def prepend
  adapters.unshift(adapter)
end
url_of(image) click to toggle source

Get URL for the provided image @return [String]

# File lib/imgproxy/url_adapters.rb, line 43
def url_of(image)
  return image if image.is_a? String
  return image.to_s if image.is_a? URI

  adapter = adapters.find { |a| a.applicable?(image) }

  return adapter.url(image) if adapter

  raise NotFound, "Can't found URL adapter for #{image.inspect}"
end