diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-01 03:09:22 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-01 03:09:22 +0000 |
commit | a2c2225d61e60c5fe534e9455b8f60bf6ae22423 (patch) | |
tree | 3dd7055ea190de5f53fc6336f6077e56c0d09e0a /lib | |
parent | a149dffe2f221544ce239658e1e0fad06a2726a2 (diff) | |
download | gitlab-ce-a2c2225d61e60c5fe534e9455b8f60bf6ae22423.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/database/type/symbolized_jsonb.rb | 28 | ||||
-rw-r--r-- | lib/serializers/symbolized_json.rb | 18 |
2 files changed, 28 insertions, 18 deletions
diff --git a/lib/gitlab/database/type/symbolized_jsonb.rb b/lib/gitlab/database/type/symbolized_jsonb.rb new file mode 100644 index 00000000000..5bec738ec9c --- /dev/null +++ b/lib/gitlab/database/type/symbolized_jsonb.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +module Gitlab + module Database + module Type + # Extends Rails' Jsonb data type to deserialize it into symbolized Hash. + # + # Example: + # + # class SomeModel < ApplicationRecord + # # some_model.a_field is of type `jsonb` + # attribute :a_field, :sym_jsonb + # end + class SymbolizedJsonb < ::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Jsonb + def type + :sym_jsonb + end + + def deserialize(value) + data = super + return unless data + + ::Gitlab::Utils.deep_symbolized_access(data) + end + end + end + end +end diff --git a/lib/serializers/symbolized_json.rb b/lib/serializers/symbolized_json.rb deleted file mode 100644 index 78192ce3132..00000000000 --- a/lib/serializers/symbolized_json.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Serializers - # Make the resulting hash have deep symbolized keys - class SymbolizedJson - class << self - def dump(obj) - obj - end - - def load(data) - return if data.nil? - - Gitlab::Utils.deep_symbolized_access(data) - end - end - end -end |