Class: Noumenon::ContentRepository
- Inherits:
-
Object
- Object
- Noumenon::ContentRepository
- Defined in:
- lib/noumenon/content_repository.rb
Overview
The base class for content repositories. This class is predominantly present just to document the expected API for a repository.
Direct Known Subclasses
Defined Under Namespace
Classes: FileSystem
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Provides access to options set on initialization.
Instance Method Summary collapse
-
#asset_url(path) ⇒ String
Returns a URL for the specified asset, without checking for it’s existence.
-
#children(root = "/", depth = 1) ⇒ Array, #each
Returns an array of content items below the root specified.
-
#get(path) ⇒ Hash, ...
Load an item from the repository.
-
#get_asset(path) ⇒ String?
Retrieves a static asset from the repository.
-
#initialize(options = {}) ⇒ ContentRepository
constructor
Create a new Repository instance.
-
#put(path, content) ⇒ Object
Save an item in the repository.
-
#save_asset(path, content) ⇒ Object
Saves a static asset to the repository.
Constructor Details
#initialize(options = {}) ⇒ ContentRepository
Create a new Repository instance.
18 19 20 |
# File 'lib/noumenon/content_repository.rb', line 18 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Provides access to options set on initialization.
12 13 14 |
# File 'lib/noumenon/content_repository.rb', line 12 def @options end |
Instance Method Details
#asset_url(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.
89 90 91 |
# File 'lib/noumenon/content_repository.rb', line 89 def asset_url(path) File.join("/assets", path) end |
#children(root = "/", depth = 1) ⇒ Array, #each
Returns an array of content items below the root specified. If depth is greater then 1 that many sub-directories will also be checked, with any items in those being placed in a ‘:children` attribute on the parent.
60 61 62 |
# File 'lib/noumenon/content_repository.rb', line 60 def children(root = "/", depth = 1) not_supported "listing children from a path" end |
#get(path) ⇒ Hash, ...
Load an item from the repository. If the item does not exist then ‘nil` should be returned.
36 37 38 |
# File 'lib/noumenon/content_repository.rb', line 36 def get(path) not_supported "reading it's contents" end |
#get_asset(path) ⇒ String?
Retrieves a static asset from the repository. If the asset does not exist nil is returned.
78 79 80 |
# File 'lib/noumenon/content_repository.rb', line 78 def get_asset(path) not_supported "loading assets" end |
#put(path, content) ⇒ Object
Save an item in the repository. If an item already exists then it should be overwritten.
27 28 29 |
# File 'lib/noumenon/content_repository.rb', line 27 def put(path, content) not_supported "updating it's contents" end |
#save_asset(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.
70 71 72 |
# File 'lib/noumenon/content_repository.rb', line 70 def save_asset(path, content) not_supported "saving assets" end |