Class: ServiceWorker::Route
- Inherits:
-
Object
- Object
- ServiceWorker::Route
- Defined in:
- lib/serviceworker/route.rb
Defined Under Namespace
Classes: AssetResolver, RouteMatch
Instance Attribute Summary collapse
-
#asset_pattern ⇒ Object
readonly
Returns the value of attribute asset_pattern.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path_pattern ⇒ Object
readonly
Returns the value of attribute path_pattern.
Class Method Summary collapse
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(path_pattern, asset_pattern = nil, options = {}) ⇒ Route
constructor
A new instance of Route.
- #match(path) ⇒ Object
Constructor Details
#initialize(path_pattern, asset_pattern = nil, options = {}) ⇒ Route
Returns a new instance of Route.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/serviceworker/route.rb', line 17 def initialize(path_pattern, asset_pattern = nil, = {}) if asset_pattern.is_a?(Hash) = asset_pattern asset_pattern = nil end @path_pattern = path_pattern @asset_pattern = asset_pattern || .fetch(:asset, path_pattern) @options = end |
Instance Attribute Details
#asset_pattern ⇒ Object (readonly)
Returns the value of attribute asset_pattern.
5 6 7 |
# File 'lib/serviceworker/route.rb', line 5 def asset_pattern @asset_pattern end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/serviceworker/route.rb', line 5 def @options end |
#path_pattern ⇒ Object (readonly)
Returns the value of attribute path_pattern.
5 6 7 |
# File 'lib/serviceworker/route.rb', line 5 def path_pattern @path_pattern end |
Class Method Details
.sprockets?(options) ⇒ Boolean
13 14 15 |
# File 'lib/serviceworker/route.rb', line 13 def self.sprockets?() .key?(:asset) end |
Instance Method Details
#headers ⇒ Object
36 37 38 |
# File 'lib/serviceworker/route.rb', line 36 def headers @options.fetch(:headers, {}) end |
#match(path) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/serviceworker/route.rb', line 28 def match(path) raise ArgumentError, "path is required" if path.to_s.strip.empty? (asset = resolver.call(path)) || (return nil) RouteMatch.new(path, asset, headers, ) end |