From 1b4a244dbc8d1e5b79feb4f111ec6183afa1b413 Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 16 Dec 2016 23:04:01 +0800 Subject: [PATCH] Rename to Gitlab::Serialize::Ci::Variables Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8088#note_20133176 --- app/models/ci/build.rb | 2 +- lib/gitlab/serialize/ci/variables.rb | 32 +++++++++++++++++++ lib/gitlab/serialize/yaml_variables.rb | 31 ------------------ .../variables_spec.rb} | 2 +- 4 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 lib/gitlab/serialize/ci/variables.rb delete mode 100644 lib/gitlab/serialize/yaml_variables.rb rename spec/lib/gitlab/serialize/{yaml_variables_spec.rb => ci/variables_spec.rb} (89%) diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 99f3f4711aa..0e30755b870 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 00000000000..0ca060cd95e --- /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 db1e7641c74..00000000000 --- 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 2691c3dc22f..797baef640c 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 -- GitLab