diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 99f3f4711aa14491f4d895704c3b424dabc53161..0e30755b870483fcb3e2a90d4047cbf4d9eaee65 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -10,7 +10,7 @@ module Ci has_many :deployments, as: :deployable serialize :options - serialize :yaml_variables, Gitlab::Serialize::YamlVariables + serialize :yaml_variables, Gitlab::Serialize::Ci::Variables validates :coverage, numericality: true, allow_blank: true validates_presence_of :ref diff --git a/lib/gitlab/serialize/ci/variables.rb b/lib/gitlab/serialize/ci/variables.rb new file mode 100644 index 0000000000000000000000000000000000000000..0ca060cd95e565a569c1372858152415d34f4ca0 --- /dev/null +++ b/lib/gitlab/serialize/ci/variables.rb @@ -0,0 +1,32 @@ +module Gitlab + module Serialize + module Ci + # This serializer could make sure our YAML variables' keys and values + # are always strings. This is more for legacy build data because + # from now on we convert them into strings before saving to database. + module Variables + extend self + + def load(string) + return unless string + + object = YAML.safe_load(string, [Symbol]) + + object.map(&Variables.method(:convert_key_value_to_string)) + end + + def dump(object) + YAML.dump(object) + end + + private + + def convert_key_value_to_string(variable) + variable[:key] = variable[:key].to_s + variable[:value] = variable[:value].to_s + variable + end + end + end + end +end diff --git a/lib/gitlab/serialize/yaml_variables.rb b/lib/gitlab/serialize/yaml_variables.rb deleted file mode 100644 index db1e7641c746ce257a3af41c81f906723e22f856..0000000000000000000000000000000000000000 --- a/lib/gitlab/serialize/yaml_variables.rb +++ /dev/null @@ -1,31 +0,0 @@ - -module Gitlab - module Serialize - # This serializer could make sure our YAML variables' keys and values - # are always strings. This is more for legacy build data because - # from now on we convert them into strings before saving to database. - module YamlVariables - extend self - - def load(string) - return unless string - - object = YAML.safe_load(string, [Symbol]) - - object.map(&YamlVariables.method(:convert_key_value_to_string)) - end - - def dump(object) - YAML.dump(object) - end - - private - - def convert_key_value_to_string(variable) - variable[:key] = variable[:key].to_s - variable[:value] = variable[:value].to_s - variable - end - end - end -end diff --git a/spec/lib/gitlab/serialize/yaml_variables_spec.rb b/spec/lib/gitlab/serialize/ci/variables_spec.rb similarity index 89% rename from spec/lib/gitlab/serialize/yaml_variables_spec.rb rename to spec/lib/gitlab/serialize/ci/variables_spec.rb index 2691c3dc22f9171c8ad3fa1b567d785e2dbec7ea..797baef640c4b399ccbbf68769f72e40ccf25bdc 100644 --- a/spec/lib/gitlab/serialize/yaml_variables_spec.rb +++ b/spec/lib/gitlab/serialize/ci/variables_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Serialize::YamlVariables do +describe Gitlab::Serialize::Ci::Variables do subject do described_class.load(described_class.dump(object)) end