Class: ServiceWorker::Route::AssetResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/serviceworker/route.rb

Constant Summary collapse

PATH_INFO =
"PATH_INFO".freeze
DEFAULT_WILDCARD_NAME =
:paths
WILDCARD_PATTERN =
%r{\/\*([^\/]*)}
NAMED_SEGMENTS_PATTERN =
%r{\/([^\/]*):([^:$\/]+)}
LEADING_SLASH_PATTERN =
%r{^\/}
INTERPOLATION_PATTERN =
Regexp.union(
  /%%/,
  /%\{(\w+)\}/, # matches placeholders like "%{foo}"
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_pattern, asset_pattern) ⇒ AssetResolver

Returns a new instance of AssetResolver.



54
55
56
57
# File 'lib/serviceworker/route.rb', line 54

def initialize(path_pattern, asset_pattern)
  @path_pattern = path_pattern
  @asset_pattern = asset_pattern
end

Instance Attribute Details

#asset_patternObject (readonly)

Returns the value of attribute asset_pattern.



52
53
54
# File 'lib/serviceworker/route.rb', line 52

def asset_pattern
  @asset_pattern
end

#path_patternObject (readonly)

Returns the value of attribute path_pattern.



52
53
54
# File 'lib/serviceworker/route.rb', line 52

def path_pattern
  @path_pattern
end

Instance Method Details

#call(path) ⇒ Object

Raises:

  • (ArgumentError)


59
60
61
62
63
64
65
# File 'lib/serviceworker/route.rb', line 59

def call(path)
  raise ArgumentError, "path is required" if path.to_s.strip.empty?

  captures = path_captures(regexp, path) or return nil

  interpolate_captures(asset_pattern, captures)
end