Class: Decidim::AssetRouter

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

Overview

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) ⇒ AssetRouter

Initializes the router.

Parameters:

  • The (ActiveStorage::Attached, ActiveStorage::Blob)

    asset to route to



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

def initialize(asset)
  @asset = asset
end

Instance Method Details

#url(**options) ⇒ Object

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

Parameters:

  • options

    The options for the URL that are the normal route options Rails route helpers accept



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

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