class Grape::Path
Represents a path to an endpoint.
Attributes
namespace[R]
raw_path[R]
settings[R]
Public Class Methods
new(raw_path, namespace, settings)
click to toggle source
# File lib/grape/path.rb, line 8 def initialize(raw_path, namespace, settings) @raw_path = raw_path @namespace = namespace @settings = settings end
Public Instance Methods
mount_path()
click to toggle source
# File lib/grape/path.rb, line 14 def mount_path settings[:mount_path] end
namespace?()
click to toggle source
# File lib/grape/path.rb, line 34 def namespace? namespace&.match?(/^\S/) && not_slash?(namespace) end
path()
click to toggle source
# File lib/grape/path.rb, line 52 def path PartsCache[parts] end
path?()
click to toggle source
# File lib/grape/path.rb, line 38 def path? raw_path&.match?(/^\S/) && not_slash?(raw_path) end
path_with_suffix()
click to toggle source
# File lib/grape/path.rb, line 56 def path_with_suffix "#{path}#{suffix}" end
root_prefix()
click to toggle source
# File lib/grape/path.rb, line 18 def root_prefix settings[:root_prefix] end
suffix()
click to toggle source
# File lib/grape/path.rb, line 42 def suffix if uses_specific_format? "(.#{settings[:format]})" elsif !uses_path_versioning? || (namespace? || path?) '(.:format)' else '(/.:format)' end end
to_s()
click to toggle source
# File lib/grape/path.rb, line 60 def to_s path_with_suffix end
uses_path_versioning?()
click to toggle source
# File lib/grape/path.rb, line 28 def uses_path_versioning? return false unless settings.key?(:version) && settings[:version_options]&.key?(:using) settings[:version] && settings[:version_options][:using] == :path end
uses_specific_format?()
click to toggle source
# File lib/grape/path.rb, line 22 def uses_specific_format? return false unless settings.key?(:format) && settings.key?(:content_types) settings[:format] && Array(settings[:content_types]).size == 1 end
Private Instance Methods
add_part(parts, value)
click to toggle source
# File lib/grape/path.rb, line 85 def add_part(parts, value) parts << value if value && not_slash?(value) end
not_slash?(value)
click to toggle source
# File lib/grape/path.rb, line 89 def not_slash?(value) value != '/' end
parts()
click to toggle source
# File lib/grape/path.rb, line 75 def parts [].tap do |parts| add_part(parts, mount_path) add_part(parts, root_prefix) parts << ':version' if uses_path_versioning? add_part(parts, namespace) add_part(parts, raw_path) end end