Module: Impression::RequestExtensions::Routing

Included in:
Qeweney::Request
Defined in:
lib/impression/request_extensions/routing.rb

Overview

Routing extensions for ‘Qeweney::Request`

Instance Method Summary collapse

Instance Method Details

#match_resource_path?(route_regexp) ⇒ String?

Matches a route regexp against the relative request path. The relative request path is a separate string (stored in ‘@resource_relative_path`) that is updated as routes are matched against it. The `route_regexp` should be either `nil` for root routes (`/`) or a Regexp of the form `/^#route(/.*)?$/`. See also `Resource#initialize`.

Parameters:

  • route_regexp (Regexp, nil)

    Route regexp to match against

Returns:

  • (String, nil)

    The remainder of the path (relative to the route)



19
20
21
22
23
24
25
26
27
28
# File 'lib/impression/request_extensions/routing.rb', line 19

def match_resource_path?(route_regexp)
  @resource_relative_path ||= path.dup

  return @resource_relative_path unless route_regexp

  # Simplified logic: no match returns nil, otherwise we set the relative path for 
  @resource_relative_path = match_resource_relative_path(
    @resource_relative_path, route_regexp
  )
end

#recalc_resource_relative_path(base_path) ⇒ String

Recalculates the relative_path from the given base path

Parameters:

  • base_path (String)

    base path

Returns:

  • (String)

    new relative path



41
42
43
44
45
# File 'lib/impression/request_extensions/routing.rb', line 41

def recalc_resource_relative_path(base_path)
  @resource_relative_path = @resource_relative_path.gsub(
    /^#{base_path}/, ''
  )
end

#resource_relative_pathString

Returns the relative_path for the latest matched resource

Returns:

  • (String)


33
34
35
# File 'lib/impression/request_extensions/routing.rb', line 33

def resource_relative_path
  @resource_relative_path ||= path
end