class Webgen::Source::Stacked

This source class is used to stack several sources together.

It serves two purposes:

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.

Attributes

stack[R]

Return the stack of [mount point, source object] entries.

Public Class Methods

new(website, map = {}) click to toggle source

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.

   # File lib/webgen/source/stacked.rb
31 def initialize(website, map = {})
32   @stack = []
33   map.each do |mp, source|
34     raise "Invalid mount point specified: #{mp}" unless mp =~ /^\//
35     @stack << [mp, source]
36   end
37 end

Public Instance Methods

paths() click to toggle source

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.

   # File lib/webgen/source/stacked.rb
43 def paths
44   if !defined?(@paths)
45     @paths = Set.new
46     @stack.each do |mp, source|
47       source.paths.each do |path|
48         @paths.add?(path.mount_at(mp))
49       end
50     end
51   end
52   @paths
53 end