diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /lib/gitlab/tracking | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'lib/gitlab/tracking')
-rw-r--r-- | lib/gitlab/tracking/standard_context.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/tracking/standard_context.rb b/lib/gitlab/tracking/standard_context.rb new file mode 100644 index 00000000000..71dfe27dd5a --- /dev/null +++ b/lib/gitlab/tracking/standard_context.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + module Tracking + class StandardContext + GITLAB_STANDARD_SCHEMA_URL = 'iglu:com.gitlab/gitlab_standard/jsonschema/1-0-1'.freeze + + def initialize(namespace: nil, project: nil, **data) + @namespace = namespace + @project = project + @data = data + end + + def namespace_id + namespace&.id + end + + def project_id + @project&.id + end + + def to_context + SnowplowTracker::SelfDescribingJson.new(GITLAB_STANDARD_SCHEMA_URL, to_h) + end + + private + + def namespace + @namespace || @project&.namespace + end + + def to_h + public_methods(false).each_with_object({}) do |method, hash| + next if method == :to_context + + hash[method] = public_send(method) # rubocop:disable GitlabSecurity/PublicSend + end.merge(@data) + end + end + end +end |