Class: Noumenon::ContentRepository

Inherits:
Object
  • Object
show all
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

FileSystem

Defined Under Namespace

Classes: FileSystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ContentRepository

Create a new Repository instance.

Parameters:

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

    A hash of options to use when configuring the repository.



18
19
20
# File 'lib/noumenon/content_repository.rb', line 18

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

Instance Attribute Details

#optionsObject (readonly)

Provides access to options set on initialization.



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

def options
  @options
end

Instance Method Details

#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.

Examples:

Noumenon.content_repository.children("/", 2)
# => [ 
#      { 
#        path: "/about", title: "About, children: [
#          { path: "/about/team", title: "The Team" },
#          { path: "/about/area", title: "The Area" }
#        ]
#      }
#    ]

Parameters:

  • root (#to_s) (defaults to: "/")

    The path to start searching from.

  • depth (Integer) (defaults to: 1)

    The number of sub-directories to check.

Returns:

  • (Array, #each)

    An array of child items.



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.

Parameters:

  • path (#to_s)

    The path to laod content from

Returns:

  • (Hash, #each, nil)

    Either the hash stored at the specified path, or nil if no content was found.



36
37
38
# File 'lib/noumenon/content_repository.rb', line 36

def get(path)
  not_supported "reading it's contents"
end

#put(path, content) ⇒ Object

Save an item in the repository. If an item already exists then it should be overwritten.

Parameters:

  • path (#to_s)

    The path the save the content at.

  • content (Hash, #each)

    A hash of key/value pairs to use as the content.



27
28
29
# File 'lib/noumenon/content_repository.rb', line 27

def put(path, content)
  not_supported "updating it's contents"
end