Sha256: 6316a8be9bb4876fd471f4552b844a1cc620a85783c9ebce72bc1ff78453e086
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
module Locomotive module Steam class AssetHostService attr_reader :request, :site, :host def initialize(request, site, host) @request, @site = request, site @host = build_host(host, request, site) end 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 ? build_url(host, source) : source add_timestamp_suffix(url, timestamp) end private def build_url(host, source) clean_source = source.sub(/\A^\//, '') URI.join(host, clean_source).to_s end def build_host(host, request, site) if host if host.respond_to?(:call) host.call(request, site) else host =~ Steam::IsHTTP ? host : "https://#{host}" end else nil end end def add_timestamp_suffix(source, timestamp) if timestamp.nil? || timestamp == 0 || source.include?('?') source else "#{source}?#{timestamp}" end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms_steam-1.3.0.rc2 | lib/locomotive/steam/services/asset_host_service.rb |
locomotivecms_steam-1.3.0.rc1 | lib/locomotive/steam/services/asset_host_service.rb |