Class: Noumenon::AssetRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/noumenon/asset_repository.rb

Direct Known Subclasses

FileSystem

Defined Under Namespace

Classes: FileSystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AssetRepository

Create a new Repository instance.

Parameters:

  • options (Hash, #each) (defaults to: {})

    A hash of options to use when configuring the repository.



12
13
14
# File 'lib/noumenon/asset_repository.rb', line 12

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Provides access to options set on initialization.



6
7
8
# File 'lib/noumenon/asset_repository.rb', line 6

def options
  @options
end

Instance Method Details

#get(path) ⇒ String?

Retrieves a static asset from the repository. If the asset does not exist nil is returned.

Parameters:

  • path (String)

    The path to load from.

Returns:

  • (String, nil)

    The asset’s content, or nil if it does not exist.



30
31
32
# File 'lib/noumenon/asset_repository.rb', line 30

def get(path)
  not_supported "loading assets"
end

#put(path, content) ⇒ Object

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.

Parameters:

  • path (String)

    The path to save the asset at.

  • content (String)

    The contents of the asset.



22
23
24
# File 'lib/noumenon/asset_repository.rb', line 22

def put(path, content)
  not_supported "saving assets"
end

#url_for(path) ⇒ String

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.

Parameters:

  • path (String)

    The asset path within the repository.

Returns:

  • (String)

    The URL to use when requesting the asset.



41
42
43
# File 'lib/noumenon/asset_repository.rb', line 41

def url_for(path)
  File.join("/assets", path)
end