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