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>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /lib/gitlab/integrations
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'lib/gitlab/integrations')
-rw-r--r--lib/gitlab/integrations/sti_type.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/gitlab/integrations/sti_type.rb b/lib/gitlab/integrations/sti_type.rb
new file mode 100644
index 00000000000..e6ea98e6d66
--- /dev/null
+++ b/lib/gitlab/integrations/sti_type.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Integrations
+ class StiType < ActiveRecord::Type::String
+ NAMESPACED_INTEGRATIONS = Set.new(%w(
+ Asana Assembla Bamboo Campfire Confluence Datadog EmailsOnPush
+ )).freeze
+
+ def cast(value)
+ new_cast(value) || super
+ end
+
+ def serialize(value)
+ new_serialize(value) || super
+ end
+
+ def deserialize(value)
+ value
+ end
+
+ def changed?(original_value, value, _new_value_before_type_cast)
+ original_value != serialize(value)
+ end
+
+ def changed_in_place?(original_value_for_database, value)
+ original_value_for_database != serialize(value)
+ end
+
+ private
+
+ def new_cast(value)
+ value = prepare_value(value)
+ return unless value
+
+ stripped_name = value.delete_suffix('Service')
+ return unless NAMESPACED_INTEGRATIONS.include?(stripped_name)
+
+ "Integrations::#{stripped_name}"
+ end
+
+ def new_serialize(value)
+ value = prepare_value(value)
+ return unless value&.starts_with?('Integrations::')
+
+ "#{value.delete_prefix('Integrations::')}Service"
+ end
+
+ # Returns value cast to a `String`, or `nil` if value is `nil`.
+ def prepare_value(value)
+ return value if value.nil? || value.is_a?(String)
+
+ value.to_s
+ end
+ end
+ end
+end