Commit 11c0d022 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify ci config node factory

parent 7c8f3b0c
...@@ -31,8 +31,8 @@ module Gitlab ...@@ -31,8 +31,8 @@ module Gitlab
private private
def create_node(key, factory) def create_node(key, factory)
factory.with_value(@value[key]) factory.with(value: @value[key])
factory.null_node unless @value.has_key?(key) factory.nullify! unless @value.has_key?(key)
factory.create! factory.create!
end end
...@@ -45,7 +45,7 @@ module Gitlab ...@@ -45,7 +45,7 @@ module Gitlab
def allow_node(symbol, entry_class, metadata) def allow_node(symbol, entry_class, metadata)
factory = Node::Factory.new(entry_class) factory = Node::Factory.new(entry_class)
.with_description(metadata[:description]) .with(description: metadata[:description])
define_method(symbol) do define_method(symbol) do
raise Entry::InvalidError unless valid? raise Entry::InvalidError unless valid?
......
...@@ -15,17 +15,12 @@ module Gitlab ...@@ -15,17 +15,12 @@ module Gitlab
@attributes = {} @attributes = {}
end end
def with_value(value) def with(attributes)
@attributes[:value] = value @attributes.merge!(attributes)
self self
end end
def with_description(description) def nullify!
@attributes[:description] = description
self
end
def null_node
@entry_class = Node::Null @entry_class = Node::Null
self self
end end
......
...@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -8,7 +8,7 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when value setting value' do context 'when value setting value' do
it 'creates entry with valid value' do it 'creates entry with valid value' do
entry = factory entry = factory
.with_value(['ls', 'pwd']) .with(value: ['ls', 'pwd'])
.create! .create!
expect(entry.value).to eq "ls\npwd" expect(entry.value).to eq "ls\npwd"
...@@ -17,8 +17,8 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -17,8 +17,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when setting description' do context 'when setting description' do
it 'creates entry with description' do it 'creates entry with description' do
entry = factory entry = factory
.with_value(['ls', 'pwd']) .with(value: ['ls', 'pwd'])
.with_description('test description') .with(description: 'test description')
.create! .create!
expect(entry.value).to eq "ls\npwd" expect(entry.value).to eq "ls\npwd"
...@@ -38,8 +38,8 @@ describe Gitlab::Ci::Config::Node::Factory do ...@@ -38,8 +38,8 @@ describe Gitlab::Ci::Config::Node::Factory do
context 'when creating a null entry' do context 'when creating a null entry' do
it 'creates a null entry' do it 'creates a null entry' do
entry = factory entry = factory
.with_value(nil) .with(value: nil)
.null_node .nullify!
.create! .create!
expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Null expect(entry).to be_an_instance_of Gitlab::Ci::Config::Node::Null
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment