class Grape::Path
Represents a path to an endpoint.
Constants
- DEFAULT_FORMAT_SEGMENT
- NO_VERSIONING_WITH_VALID_PATH_FORMAT_SEGMENT
- VERSION_SEGMENT
Attributes
Public Class Methods
Source
# File lib/grape/path.rb, line 12 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
Public Instance Methods
Private Instance Methods
Source
# File lib/grape/path.rb, line 43 def add_part(parts, value) parts << value if value && not_slash?(value) end
Source
# File lib/grape/path.rb, line 33 def build_parts(raw_path, raw_namespace, settings) [].tap do |parts| add_part(parts, settings[:mount_path]) add_part(parts, settings[:root_prefix]) parts << VERSION_SEGMENT if uses_path_versioning?(settings) add_part(parts, raw_namespace) add_part(parts, raw_path) end end
Source
# File lib/grape/path.rb, line 23 def build_suffix(raw_path, raw_namespace, settings) if uses_specific_format?(settings) "(.#{settings[:format]})" elsif !uses_path_versioning?(settings) || (valid_part?(raw_namespace) || valid_part?(raw_path)) NO_VERSIONING_WITH_VALID_PATH_FORMAT_SEGMENT else DEFAULT_FORMAT_SEGMENT end end
Source
# File lib/grape/path.rb, line 57 def uses_path_versioning?(settings) return false unless settings.key?(:version) && settings[:version_options]&.key?(:using) settings[:version] && settings[:version_options][:using] == :path end
Source
# File lib/grape/path.rb, line 51 def uses_specific_format?(settings) return false unless settings.key?(:format) && settings.key?(:content_types) settings[:format] && Array(settings[:content_types]).size == 1 end
Source
# File lib/grape/path.rb, line 63 def valid_part?(part) part&.match?(/^\S/) && not_slash?(part) end