Class: Decidim::AssetRouter::Storage

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/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.

Parameters:

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

    asset to route to



14
15
16
# File 'decidim-core/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.

Parameters:

  • options

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



22
23
24
25
26
27
28
# File 'decidim-core/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
    representation_url(**options)
  end
end