instance method
compute_asset_host
Ruby on Rails 6.1.7.10
Since v4.0.13Signature
compute_asset_host(source = "", options = {})
Pick an asset host for this source. Returns nil if no host is set, the host if no wildcard is set, the host interpolated with the numbers 0-3 if it contains %d (the number is the source hash mod 4), or the value returned from invoking call on an object responding to call (proc or otherwise).
Parameters
-
sourceopt = "" -
optionsopt = {}
Source
# File actionview/lib/action_view/helpers/asset_url_helper.rb, line 276
def compute_asset_host(source = "", options = {})
request = self.request if respond_to?(:request)
host = options[:host]
host ||= config.asset_host if defined? config.asset_host
if host
if host.respond_to?(:call)
arity = host.respond_to?(:arity) ? host.arity : host.method(:call).arity
args = [source]
args << request if request && (arity > 1 || arity < 0)
host = host.call(*args)
elsif host.include?("%d")
host = host % (Zlib.crc32(source) % 4)
end
end
host ||= request.base_url if request && options[:protocol] == :request
return unless host
if URI_REGEXP.match?(host)
host
else
protocol = options[:protocol] || config.default_asset_host_protocol || (request ? :request : :relative)
case protocol
when :relative
"//#{host}"
when :request
"#{request.protocol}#{host}"
else
"#{protocol}://#{host}"
end
end
end
Defined in actionview/lib/action_view/helpers/asset_url_helper.rb line 276
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::AssetUrlHelper