Class: Decidim::AssetRouter::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/asset_router/storage.rb

Overview

Storage asset router provides global access to the asset routes for assets saved through ActiveStorage. This handles the different cases for routing to the remote routes when using an assets CDN or to local routes when using the local disk storage driver.

Instance Method Summary collapse

Constructor Details

#initialize(asset) ⇒ Storage

Initializes the router.



14
15
16
# File 'lib/decidim/asset_router/storage.rb', line 14

def initialize(asset)
  @asset = asset
end

Instance Method Details

#url(**options) ⇒ Object

Generates the correct URL to the asset with the provided options.



22
23
24
25
26
27
28
# File 'lib/decidim/asset_router/storage.rb', line 22

def url(**options)
  if asset.is_a? ActiveStorage::Attached
    routes.rails_blob_url(asset.blob, **default_options.merge(options))
  else
    routes.rails_representation_url(asset, **default_options.merge(options))
  end
end