Class: Webgen::Source::Resource
- Inherits:
-
Object
- Object
- Webgen::Source::Resource
- Includes:
- WebsiteAccess
- Defined in:
- lib/webgen/source/resource.rb
Overview
This class is used to provide access to sources provided by resources.
Instance Attribute Summary collapse
-
#glob ⇒ Object
readonly
The glob (see File.fnmatch) specifying the resources.
-
#paths_glob ⇒ Object
readonly
The glob (see File.fnmatch) specifying the paths that should be used from the resources.
-
#strip_prefix ⇒ Object
readonly
The prefix that should optionally be stripped from the paths.
Instance Method Summary collapse
-
#initialize(glob, paths_glob = nil, strip_prefix = nil) ⇒ Resource
constructor
Create a new resource source for the the
glob
and use only those paths matchingpaths_glob
while strippingstrip_prefix
off the path. -
#paths ⇒ Object
Return all paths associated with the resources identified by #glob.
Methods included from WebsiteAccess
Constructor Details
#initialize(glob, paths_glob = nil, strip_prefix = nil) ⇒ Resource
Create a new resource source for the the glob
and use only those paths matching paths_glob
while stripping strip_prefix
off the path.
24 25 26 |
# File 'lib/webgen/source/resource.rb', line 24 def initialize(glob, paths_glob = nil, strip_prefix = nil) @glob, @paths_glob, @strip_prefix = glob, paths_glob, strip_prefix end |
Instance Attribute Details
#glob ⇒ Object (readonly)
The glob (see File.fnmatch) specifying the resources.
14 15 16 |
# File 'lib/webgen/source/resource.rb', line 14 def glob @glob end |
#paths_glob ⇒ Object (readonly)
The glob (see File.fnmatch) specifying the paths that should be used from the resources.
17 18 19 |
# File 'lib/webgen/source/resource.rb', line 17 def paths_glob @paths_glob end |
#strip_prefix ⇒ Object (readonly)
The prefix that should optionally be stripped from the paths.
20 21 22 |
# File 'lib/webgen/source/resource.rb', line 20 def strip_prefix @strip_prefix end |
Instance Method Details
#paths ⇒ Object
Return all paths associated with the resources identified by #glob.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webgen/source/resource.rb', line 29 def paths if !defined?(@paths) stack = Stacked.new website.config['resources'].select {|name, infos| File.fnmatch(@glob, name)}.sort.each do |name, infos| stack.add([['/', constant(infos.first).new(*infos[1..-1])]]) end @paths = stack.paths @paths = @paths.select {|p| File.fnmatch(@paths_glob, p)} if @paths_glob @paths.collect! {|p| p.mount_at('/', @strip_prefix)} if @strip_prefix end @paths end |