Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Make PathHelper routing independent (#9186)

ulfertsbf9639243df9
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index ba6f035b18a..608c99a3a5c 100644
--- a/lib/api/v3/utilities/path_helper.rb
+++ b/lib/api/v3/utilities/path_helper.rb
@@ -49,33 +49,30 @@ module API
private_class_method :index
def self.show(name)
- define_singleton_method(name) do |id|
- "#{send(name.to_s.pluralize)}/#{id}"
- end
+ define_singleton_method(name) { |id| build_path(name, id) }
end
private_class_method :show
def self.create_form(name)
- define_singleton_method(:"create_#{name}_form") do
- "#{send(name.to_s.pluralize)}/form"
- end
+ define_singleton_method(:"create_#{name}_form") { build_path(name, "form") }
end
private_class_method :create_form
def self.update_form(name)
- define_singleton_method(:"#{name}_form") do |id|
- "#{send(name, id)}/form"
- end
+ define_singleton_method(:"#{name}_form") { |id| build_path(name, id, "form") }
end
private_class_method :update_form
def self.schema(name)
- define_singleton_method(:"#{name}_schema") do
- "#{send(name.to_s.pluralize)}/schema"
- end
+ define_singleton_method(:"#{name}_schema") { build_path(name, "schema") }
end
private_class_method :schema
+ def self.build_path(name, *kwargs)
+ [root, name.to_s.pluralize, *kwargs].compact.join("/")
+ end
+ private_class_method :build_path
+
def self.resources(name,
except: [],
only: %i[index show create_form update_form schema])