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

Moved match() from ServiceResult to a refinement module

Andreas Pfohl10ffbe6364da
diff --git a/app/services/service_result.rb b/app/services/service_result.rb
index 902ee59387a..834d99eb3f9 100644
--- a/app/services/service_result.rb
+++ b/app/services/service_result.rb
@@ -169,14 +169,6 @@ class ServiceResult
self
end
- def match(on_success:, on_failure:)
- if success?
- on_success.call(result)
- else
- on_failure.call(result)
- end
- end
-
def each
yield result if success?
self
diff --git a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
index 006ef200647..6cb45b90640 100644
--- a/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
+++ b/modules/storages/lib/api/v3/storage_files/storage_files_api.rb
@@ -28,6 +28,8 @@
module API::V3::StorageFiles
class StorageFilesAPI < ::API::OpenProjectAPI
+ using ::API::V3::Utilities::ServiceResultRefinements
+
helpers do
def handle_files_error(files)
case files.result
diff --git a/modules/storages/lib/api/v3/utilities/service_result_refinements.rb b/modules/storages/lib/api/v3/utilities/service_result_refinements.rb
new file mode 100644
index 00000000000..605b06ae774
--- /dev/null
+++ b/modules/storages/lib/api/v3/utilities/service_result_refinements.rb
@@ -0,0 +1,11 @@
+module API::V3::Utilities::ServiceResultRefinements
+ refine ServiceResult do
+ def match(on_success:, on_failure:)
+ if success?
+ on_success.call(result)
+ else
+ on_failure.call(result)
+ end
+ end
+ end
+end
diff --git a/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb b/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb
index 17a68aabb02..fa0b8ad75aa 100644
--- a/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb
+++ b/modules/storages/lib/api/v3/utilities/storage_interaction/storage_queries.rb
@@ -1,5 +1,7 @@
module API::V3::Utilities::StorageInteraction
class StorageQueries
+ using ::API::V3::Utilities::ServiceResultRefinements
+
def initialize(uri:, provider_type:, user:, oauth_client:)
@uri = uri
@provider_type = provider_type