class ServiceWorker::Router
Constants
- PATH_INFO
Attributes
routes[R]
Public Class Methods
default()
click to toggle source
# File lib/serviceworker/router.rb, line 7 def self.default new.draw_default end
new()
click to toggle source
# File lib/serviceworker/router.rb, line 13 def initialize @routes = [] draw(&Proc.new) if block_given? end
Public Instance Methods
any?()
click to toggle source
# File lib/serviceworker/router.rb, line 48 def any? @routes.any? end
draw() { |self| ... }
click to toggle source
# File lib/serviceworker/router.rb, line 19 def draw(&block) return self unless block_given? if block.arity == 1 yield(self) else instance_eval(&block) end self end
draw_default()
click to toggle source
# File lib/serviceworker/router.rb, line 31 def draw_default draw { get "/serviceworker.js" } end
match(path, *args)
click to toggle source
# File lib/serviceworker/router.rb, line 35 def match(path, *args) if path.is_a?(Hash) opts = path.to_a path, asset = opts.shift args = [asset, opts.to_h] end Route.new(path, *args).tap do |route| @routes << route end end
Also aliased as: get
match_route(env)
click to toggle source
# File lib/serviceworker/router.rb, line 52 def match_route(env) path = env[PATH_INFO] @routes.each do |route| match = route.match(path) and return match end nil end