Class: Imgproxy::UrlAdapters
- Inherits:
-
Object
- Object
- Imgproxy::UrlAdapters
- Defined in:
- lib/imgproxy/url_adapters.rb,
lib/imgproxy/url_adapters/shrine.rb,
lib/imgproxy/url_adapters/shrine_s3.rb,
lib/imgproxy/url_adapters/active_storage.rb,
lib/imgproxy/url_adapters/active_storage_s3.rb,
lib/imgproxy/url_adapters/active_storage_gcs.rb
Overview
Defined Under Namespace
Classes: ActiveStorage, ActiveStorageGCS, ActiveStorageS3, NotConfigured, NotFound, Shrine, ShrineS3
Instance Attribute Summary collapse
-
#adapters ⇒ Array
readonly
Currently added adapters.
Instance Method Summary collapse
-
#add(adapter) ⇒ Array
Add adapter to the end of the list.
-
#clear! ⇒ Array
Remove all adapters from the list.
-
#initialize ⇒ UrlAdapters
constructor
A new instance of UrlAdapters.
-
#prepend ⇒ Array
Add adapter to the beginning of the list.
-
#url_of(image) ⇒ String
Get URL for the provided image.
Constructor Details
#initialize ⇒ UrlAdapters
Returns a new instance of UrlAdapters.
23 24 25 |
# File 'lib/imgproxy/url_adapters.rb', line 23 def initialize @adapters = [] end |
Instance Attribute Details
#adapters ⇒ Array (readonly)
Returns Currently added adapters.
21 22 23 |
# File 'lib/imgproxy/url_adapters.rb', line 21 def adapters @adapters end |
Instance Method Details
#add(adapter) ⇒ Array
Add adapter to the end of the list
29 30 31 |
# File 'lib/imgproxy/url_adapters.rb', line 29 def add(adapter) adapters << adapter end |
#clear! ⇒ Array
Remove all adapters from the list
41 42 43 |
# File 'lib/imgproxy/url_adapters.rb', line 41 def clear! @adapters = [] end |
#prepend ⇒ Array
Add adapter to the beginning of the list
35 36 37 |
# File 'lib/imgproxy/url_adapters.rb', line 35 def prepend adapters.unshift(adapter) end |
#url_of(image) ⇒ String
Get URL for the provided image
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/imgproxy/url_adapters.rb', line 47 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 |