Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (39 sloc)
1.03 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module CarrierWave | |
module Uploader | |
module Url | |
extend ActiveSupport::Concern | |
include CarrierWave::Uploader::Configuration | |
include CarrierWave::Utilities::Uri | |
## | |
# === Parameters | |
# | |
# [Hash] optional, the query params (only AWS) | |
# | |
# === Returns | |
# | |
# [String] the location where this file is accessible via a url | |
# | |
def url(options = {}) | |
if file.respond_to?(:url) | |
tmp_url = file.method(:url).arity.zero? ? file.url : file.url(options) | |
return tmp_url if tmp_url.present? | |
end | |
if file.respond_to?(:path) | |
path = encode_path(file.path.sub(File.expand_path(root), '')) | |
if host = asset_host | |
if host.respond_to? :call | |
"#{host.call(file)}#{path}" | |
else | |
"#{host}#{path}" | |
end | |
else | |
(base_path || "") + path | |
end | |
end | |
end | |
def to_s | |
url || '' | |
end | |
end # Url | |
end # Uploader | |
end # CarrierWave |