Class: ServiceWorker::Route::AssetResolver

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

Constant Summary collapse

PATH_INFO =
"PATH_INFO"
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.



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

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.



57
58
59
# File 'lib/serviceworker/route.rb', line 57

def asset_pattern
  @asset_pattern
end

#path_patternObject (readonly)

Returns the value of attribute path_pattern.



57
58
59
# File 'lib/serviceworker/route.rb', line 57

def path_pattern
  @path_pattern
end

Instance Method Details

#call(path) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
# File 'lib/serviceworker/route.rb', line 64

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

  (captures = path_captures(regexp, path)) || (return nil)

  interpolate_captures(asset_pattern, captures)
end