class Shrine::Derivation::Url

Public Instance Methods

call(host: nil, prefix: nil, **options) click to toggle source
# File lib/shrine/plugins/derivation_endpoint.rb, line 306
def call(host: nil, prefix: nil, **options)
  base_url = [host, *prefix].join("/")
  path = path_identifier(metadata: options.delete(:metadata))

  if signer
    url = [base_url, path].join("/")
    signer.call(url, **options)
  else
    signed_part = signed_url("#{path}?#{query(**options)}")
    [base_url, signed_part].join("/")
  end
end

Private Instance Methods

path_identifier(metadata: []) click to toggle source
# File lib/shrine/plugins/derivation_endpoint.rb, line 321
def path_identifier(metadata: [])
  [
    name,
    *args,
    source.urlsafe_dump(metadata: metadata)
  ].map{|component| Rack::Utils.escape_path(component.to_s)}.join('/')
end
query(expires_in: nil, type: nil, filename: nil, disposition: nil, version: nil) click to toggle source
# File lib/shrine/plugins/derivation_endpoint.rb, line 329
def query(expires_in: nil,
          type: nil,
          filename: nil,
          disposition: nil,
          version: nil)

  params = {}
  params[:expires_at]  = (Time.now + expires_in).to_i if expires_in
  params[:version]     = version if version
  params[:type]        = type if type
  params[:filename]    = filename if filename
  params[:disposition] = disposition if disposition

  Rack::Utils.build_query(params)
end
signed_url(url) click to toggle source
# File lib/shrine/plugins/derivation_endpoint.rb, line 345
def signed_url(url)
  signer = UrlSigner.new(secret_key)
  signer.sign_url(url)
end