Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /lib/gitlab/global_id.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'lib/gitlab/global_id.rb')
-rw-r--r--lib/gitlab/global_id.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/gitlab/global_id.rb b/lib/gitlab/global_id.rb
index cc82b6c5897..e8a6006dce1 100644
--- a/lib/gitlab/global_id.rb
+++ b/lib/gitlab/global_id.rb
@@ -2,6 +2,8 @@
module Gitlab
module GlobalId
+ CoerceError = Class.new(ArgumentError)
+
def self.build(object = nil, model_name: nil, id: nil, params: nil)
if object
model_name ||= object.class.name
@@ -10,5 +12,20 @@ module Gitlab
::URI::GID.build(app: GlobalID.app, model_name: model_name, model_id: id, params: params)
end
+
+ def self.as_global_id(value, model_name: nil)
+ case value
+ when GlobalID
+ value
+ when URI::GID
+ GlobalID.new(value)
+ when Integer
+ raise CoerceError, 'Cannot coerce Integer' unless model_name.present?
+
+ GlobalID.new(::Gitlab::GlobalId.build(model_name: model_name, id: value))
+ else
+ raise CoerceError, "Invalid ID. Cannot coerce instances of #{value.class}"
+ end
+ end
end
end