lib/grape/path.rb in grape-1.3.0 vs lib/grape/path.rb in grape-1.3.1
- old
+ new
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+require 'grape/util/cache'
+
module Grape
# Represents a path to an endpoint.
class Path
def self.prepare(raw_path, namespace, settings)
Path.new(raw_path, namespace, settings)
@@ -56,11 +58,11 @@
'(/.:format)'
end
end
def path
- Grape::Router.normalize_path(parts.join('/'))
+ Grape::Router.normalize_path(PartsCache[parts])
end
def path_with_suffix
"#{path}#{suffix}"
end
@@ -68,9 +70,17 @@
def to_s
path_with_suffix
end
private
+
+ class PartsCache < Grape::Util::Cache
+ def initialize
+ @cache = Hash.new do |h, parts|
+ h[parts] = -parts.join('/')
+ end
+ end
+ end
def parts
parts = [mount_path, root_prefix].compact
parts << ':version' if uses_path_versioning?
parts << namespace.to_s