Class: Locomotive::Steam::AssetHostService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, site, host) ⇒ AssetHostService

Returns a new instance of AssetHostService.



8
9
10
11
12
# File 'lib/locomotive/steam/services/asset_host_service.rb', line 8

def initialize(request, site, host)
  @request, @site = request, site

  @host = build_host(host, request, site)
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



6
7
8
# File 'lib/locomotive/steam/services/asset_host_service.rb', line 6

def host
  @host
end

#requestObject (readonly)

Returns the value of attribute request.



6
7
8
# File 'lib/locomotive/steam/services/asset_host_service.rb', line 6

def request
  @request
end

#siteObject (readonly)

Returns the value of attribute site.



6
7
8
# File 'lib/locomotive/steam/services/asset_host_service.rb', line 6

def site
  @site
end

Instance Method Details

#compute(source, timestamp = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/locomotive/steam/services/asset_host_service.rb', line 14

def compute(source, timestamp = nil)
  return source if source.blank?

  timestamp ||= (site.try(:template_version) || site.try(:updated_at)).to_i

  return add_timestamp_suffix(source, timestamp) if source =~ Steam::IsHTTP

  url = self.host ? URI.join(host, source).to_s : source

  add_timestamp_suffix(url, timestamp)
end