Class: Webgen::Source::Stacked
- Inherits:
-
Object
- Object
- Webgen::Source::Stacked
- Defined in:
- lib/webgen/source/stacked.rb
Overview
This source class is used to stack several sources together.
It serves two purposes:
-
First, it can be used to access more than one source. This is useful when your website consists of more than one source directory and you want to use all of them.
-
Second, sources can be mounted on specific directories. For example, a folder with images that you don’t want to copy to the main website source directory can be mounted under ‘/images’ so that they are available nonetheless.
Also be aware that when a path is returned by a source that has already be returned by a prior source, it is discarded and not used.
Instance Attribute Summary collapse
-
#stack ⇒ Object
readonly
Return the stack of [mount point, source object] entries.
Instance Method Summary collapse
-
#initialize(website, map = {}) ⇒ Stacked
constructor
Create a new stack.
-
#paths ⇒ Object
Return all paths returned by the sources in the stack.
Constructor Details
#initialize(website, map = {}) ⇒ Stacked
Create a new stack.
The optional map
parameter is used to provide mappings of mount points to source objects. It should be an array of two-element arrays which contain an absolute directory (ie. starting and ending with a slash) and a source object.
32 33 34 35 36 37 38 |
# File 'lib/webgen/source/stacked.rb', line 32 def initialize(website, map = {}) @stack = [] map.each do |mp, source| raise "Invalid mount point specified: #{mp}" unless mp =~ /^\// @stack << [mp, source] end end |
Instance Attribute Details
#stack ⇒ Object (readonly)
Return the stack of [mount point, source object] entries.
25 26 27 |
# File 'lib/webgen/source/stacked.rb', line 25 def stack @stack end |
Instance Method Details
#paths ⇒ Object
Return all paths returned by the sources in the stack.
Since the stack is ordered, paths returned by later source objects are not used if a prior source object has returned the same path.
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/webgen/source/stacked.rb', line 44 def paths if !defined?(@paths) @paths = Set.new @stack.each do |mp, source| source.paths.each do |path| @paths.add?(path.mount_at(mp)) end end end @paths end |