Sha256: fcb0e75753786856fdda57b0c67d96439fb1b7f03d27ee27613571f119e31583

Contents?: true

Size: 1.03 KB

Versions: 10

Compression:

Stored size: 1.03 KB

Contents

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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
carrierwave-3.1.0.beta lib/carrierwave/uploader/url.rb
carrierwave-3.0.7 lib/carrierwave/uploader/url.rb
carrierwave-3.0.6 lib/carrierwave/uploader/url.rb
carrierwave-3.0.5 lib/carrierwave/uploader/url.rb
carrierwave-3.0.4 lib/carrierwave/uploader/url.rb
carrierwave-3.0.3 lib/carrierwave/uploader/url.rb
carrierwave-3.0.2 lib/carrierwave/uploader/url.rb
carrierwave-3.0.1 lib/carrierwave/uploader/url.rb
carrierwave-3.0.0 lib/carrierwave/uploader/url.rb
carrierwave-3.0.0.rc lib/carrierwave/uploader/url.rb