Sha256: 6820613a3d7098bf3e5246f45131cd955e85b1726b015ac239a82eb125dc7da8

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

# Blob URI methods for accessing a blob via the web. 
# Exclusively for the Blob class.

class Blob

  # Get the blob URI's dir name e.g. "/my/photos".
  #
  # This impl calls #dir which is typically fine.
  #
  # Override this if the local storage file dir
  # name is different than the generic base name.
  #
  # @return [String] the blob URI's dir name
  #
  def uri_dir
    dir
  end

  # Get the blob's URI base name e.g. "photo.jpg".
  #
  # This impl calls #base which is typically fine.
  #
  # Override this when the URI base name
  # is different than the generic base name.
  #
  # @return [String] the blob URI's base name
  #
  def uri_base    
    base
  end

  # Get the blob's URI to access this blob from the web.
  #
  # This impl calls #uri_dir and #uri_base.
  # Override this e.g. for assets, CDNs, etc.
  #
  # @return [String] the blob URI's path
  #
  def uri
    return "/#{uri_dir}/#{uri_base}"
  end

  # Get the blob's URI to access this blob from the web,
  # with a random chaff query appended as a cache buster.
  #
  # @return [String] the blob URI's path?uuid=chaff
  #
  def uri_cacheless
    return "#{uri}?cacheless=#{SecureRandom.uuid}"
  end

  # Deprecated
  #
  def url
    raise "Deprecated: replace with #uri"
  end

  # Deprecated
  #
  def url_cacheless
    raise "Deprecated: replace with #uri_cacheless"
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sixarm_ruby_blob-1.0.3 lib/sixarm_ruby_blob/uri.rb
sixarm_ruby_blob-1.0.1 lib/sixarm_ruby_blob/uri.rb