Module: Gitlab::GlobalId
- Defined in:
- lib/gitlab/global_id.rb,
lib/gitlab/global_id/deprecations.rb
Defined Under Namespace
Modules: Deprecations
Constant Summary collapse
- CoerceError =
Class.new(ArgumentError)
Class Method Summary collapse
- .as_global_id(value, model_name: nil) ⇒ Object
- .build(object = nil, model_name: nil, id: nil, params: nil) ⇒ Object
Class Method Details
.as_global_id(value, model_name: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/global_id.rb', line 16 def self.as_global_id(value, model_name: nil) case value when GlobalID value when URI::GID GlobalID.new(value) when Integer, String raise CoerceError, "Cannot coerce #{value.class}" 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 |
.build(object = nil, model_name: nil, id: nil, params: nil) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/gitlab/global_id.rb', line 7 def self.build(object = nil, model_name: nil, id: nil, params: nil) if object model_name ||= object.class.name id ||= object.id end ::URI::GID.build(app: GlobalID.app, model_name: model_name, model_id: id, params: params) end |