Class: Roadie::PathRewriterProvider
- Inherits:
-
Object
- Object
- Roadie::PathRewriterProvider
- Defined in:
- lib/roadie/path_rewriter_provider.rb
Overview
This provider acts a bit like a pipeline in normal UNIX parlour by enabling you to make changes to the requested path. Some uses of this include:
* Convert absolute URLs into local filesystem paths.
* Convert between external DNS name into internal naming.
* Changing path structure of filenames.
* Removing digests from filenames.
* Handle query string logic.
* Skipping known-bad paths.
There might be other useful things you could use it for. The basic premise is that a path is sent in to this provider, maybe modified and then passed on to the “upstream” provider (or ProviderList).
If the block returns nil or false, the upstream provider will not be invoked and it will be treated as “not found”. This makes it possible to use this provider as a filter only.
Instance Attribute Summary collapse
- #filter ⇒ Object readonly
- #provider ⇒ Object readonly
Instance Method Summary collapse
- #find_stylesheet(path) ⇒ Object
- #find_stylesheet!(path) ⇒ Object
-
#initialize(provider, &filter) ⇒ PathRewriterProvider
constructor
A new instance of PathRewriterProvider.
Constructor Details
#initialize(provider, &filter) ⇒ PathRewriterProvider
Returns a new instance of PathRewriterProvider.
47 48 49 50 |
# File 'lib/roadie/path_rewriter_provider.rb', line 47 def initialize(provider, &filter) @provider = provider @filter = filter end |
Instance Attribute Details
#filter ⇒ Object (readonly)
45 46 47 |
# File 'lib/roadie/path_rewriter_provider.rb', line 45 def filter @filter end |
#provider ⇒ Object (readonly)
45 46 47 |
# File 'lib/roadie/path_rewriter_provider.rb', line 45 def provider @provider end |
Instance Method Details
#find_stylesheet(path) ⇒ Object
52 53 54 55 |
# File 'lib/roadie/path_rewriter_provider.rb', line 52 def find_stylesheet(path) new_path = filter.call(path) provider.find_stylesheet(new_path) if new_path end |
#find_stylesheet!(path) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/roadie/path_rewriter_provider.rb', line 57 def find_stylesheet!(path) new_path = filter.call(path) if new_path provider.find_stylesheet!(new_path) else raise CssNotFound.new( css_name: path, message: "Filter returned #{new_path.inspect}" ) end end |