Rename to Gitlab::Serialize::Ci::Variables
Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8088#note_20133176
This commit is contained in:
parent
cc1eb7fec5
commit
1b4a244dbc
4 changed files with 34 additions and 33 deletions
|
@ -10,7 +10,7 @@ module Ci
|
||||||
has_many :deployments, as: :deployable
|
has_many :deployments, as: :deployable
|
||||||
|
|
||||||
serialize :options
|
serialize :options
|
||||||
serialize :yaml_variables, Gitlab::Serialize::YamlVariables
|
serialize :yaml_variables, Gitlab::Serialize::Ci::Variables
|
||||||
|
|
||||||
validates :coverage, numericality: true, allow_blank: true
|
validates :coverage, numericality: true, allow_blank: true
|
||||||
validates_presence_of :ref
|
validates_presence_of :ref
|
||||||
|
|
32
lib/gitlab/serialize/ci/variables.rb
Normal file
32
lib/gitlab/serialize/ci/variables.rb
Normal file
|
@ -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
|
|
@ -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
|
|
|
@ -1,6 +1,6 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Gitlab::Serialize::YamlVariables do
|
describe Gitlab::Serialize::Ci::Variables do
|
||||||
subject do
|
subject do
|
||||||
described_class.load(described_class.dump(object))
|
described_class.load(described_class.dump(object))
|
||||||
end
|
end
|
Loading…
Reference in a new issue