Sha256: 61b74f290b23ba0f3b3a9b4f3a9afa23023d0cca7d949c5f732cc04a627436f4

Contents?: true

Size: 1.69 KB

Versions: 4

Compression:

Stored size: 1.69 KB

Contents

class Noumenon::AssetRepository
  autoload :FileSystem, 'noumenon/asset_repository/file_system'
  
  # Provides access to options set on initialization.
  # @api public
  attr_reader :options
  
  # Create a new Repository instance.
  #
  # @param [ Hash, #each ] options A hash of options to use when configuring the repository.
  # @api public
  def initialize(options = {})
    @options = options
  end
  
  # Saves a static asset to the repository. To be saved the asset must have a file extension, to prevent
  # problems with an entire directory being overridden by a single asset.
  #
  # @param [ String ] path The path to save the asset at.
  # @param [ String ] content The contents of the asset.
  # @raises [ ArgumentError ] The path did not have a file extension.
  def put(path, content)
    not_supported "saving assets"
  end
  
  # Retrieves a static asset from the repository. If the asset does not exist nil is returned.
  #
  # @param [ String ] path The path to load from.
  # @return [ String, nil ] The asset's content, or nil if it does not exist.
  def get(path)
    not_supported "loading assets"
  end
  
  # Returns a URL for the specified asset, without checking for it's existence.
  #
  # This is most useful for repositories that save their assets to a CDN such as S3, and allows them to be
  # directly accessed from there, instead of downloaded and then retransmitted.
  #
  # @param [ String ] path The asset path within the repository.
  # @return [ String ] The URL to use when requesting the asset.
  def url_for(path)
    File.join("/assets", path)
  end

  protected
  def not_supported(action)
    raise NotImplementedError.new("This repository type does not support #{action}.")
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
noumenon-0.2.3 lib/noumenon/asset_repository.rb
noumenon-0.2.2 lib/noumenon/asset_repository.rb
noumenon-0.2.1 lib/noumenon/asset_repository.rb
noumenon-0.2.0 lib/noumenon/asset_repository.rb