Class: Grape::Router::Pattern::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/grape/router/pattern/path.rb

Overview

Assembles the path template a Grape::Router::Pattern compiles into a matcher. It turns a raw path plus the path-settings snapshot taken by Util::InheritableSetting#path_settings (mount paths, root prefix, path-versioning and format) into an origin (the route prefix) and a suffix (the format segment). build is the entry point that wires this into pattern construction.

Defined Under Namespace

Classes: PartsCache

Constant Summary collapse

DEFAULT_FORMAT_SEGMENT =
'(/.:format)'
NO_VERSIONING_WITH_VALID_PATH_FORMAT_SEGMENT =
'(.:format)'
VERSION_SEGMENT =
':version'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_path, raw_namespace, settings) ⇒ Path

Returns a new instance of Path.



19
20
21
22
# File 'lib/grape/router/pattern/path.rb', line 19

def initialize(raw_path, raw_namespace, settings)
  @origin = PartsCache[build_parts(raw_path, raw_namespace, settings)]
  @suffix = build_suffix(raw_path, raw_namespace, settings)
end

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



17
18
19
# File 'lib/grape/router/pattern/path.rb', line 17

def origin
  @origin
end

#suffixObject (readonly)

Returns the value of attribute suffix.



17
18
19
# File 'lib/grape/router/pattern/path.rb', line 17

def suffix
  @suffix
end

Instance Method Details

#to_sObject



24
25
26
# File 'lib/grape/router/pattern/path.rb', line 24

def to_s
  "#{origin}#{suffix}"
end