Class: Locomotive::Steam::ThemeAssetUrlService

Inherits:
Object
  • Object
show all
Defined in:
lib/locomotive/steam/services/theme_asset_url_service.rb

Instance Method Summary collapse

Instance Method Details

#build(path) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/locomotive/steam/services/theme_asset_url_service.rb', line 8

def build(path)
  # keep the query string safe
  path.gsub!(/(\?+.+)$/, '')
  query_string = $1

  # build the url of the theme asset based on the persistence layer
  _url = repository.url_for(path)

  # get a timestamp only if the source url doesn't include a query string
  timestamp = query_string.blank? ? checksums[path] : nil

  # prefix by a asset host if given
  url = asset_host ? asset_host.compute(_url, timestamp) : _url

  query_string ? "#{url}#{query_string}" : url
end

#checksum?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/locomotive/steam/services/theme_asset_url_service.rb', line 33

def checksum?
  !!checksum
end

#checksumsObject



25
26
27
28
29
30
31
# File 'lib/locomotive/steam/services/theme_asset_url_service.rb', line 25

def checksums
  if checksum?
    @checksums ||= fetch_checksums
  else
    {}
  end
end