Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
cc373a35
Commit
cc373a35
authored
Jun 10, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add factory for fabricating new ci config nodes
parent
5abfc7fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
21 deletions
+106
-21
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+7
-17
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+6
-4
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+44
-0
spec/lib/gitlab/ci/config/node/factory_spec.rb
spec/lib/gitlab/ci/config/node/factory_spec.rb
+49
-0
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
cc373a35
...
@@ -30,19 +30,10 @@ module Gitlab
...
@@ -30,19 +30,10 @@ module Gitlab
private
private
def
add_node
(
key
,
metadata
)
def
create_node
(
key
,
factory
)
entry
=
create_entry
(
key
,
metadata
[
:class
])
factory
.
with_value
(
@value
[
key
])
entry
.
description
=
metadata
[
:description
]
factory
.
null_node
unless
@value
.
has_key?
(
key
)
factory
.
create!
@nodes
[
key
]
=
entry
end
def
create_entry
(
key
,
entry_class
)
if
@value
.
has_key?
(
key
)
entry_class
.
new
(
@value
[
key
])
else
Node
::
Null
.
new
(
nil
)
end
end
end
class_methods
do
class_methods
do
...
@@ -51,9 +42,8 @@ module Gitlab
...
@@ -51,9 +42,8 @@ module Gitlab
private
private
def
allow_node
(
symbol
,
entry_class
,
metadata
)
def
allow_node
(
symbol
,
entry_class
,
metadata
)
node
=
{
symbol
.
to_sym
=>
factory
=
Node
::
Factory
.
new
(
entry_class
)
{
class:
entry_class
,
.
with_description
(
metadata
[
:description
])
description:
metadata
[
:description
]
}
}
define_method
(
symbol
)
do
define_method
(
symbol
)
do
raise
Entry
::
InvalidError
unless
valid?
raise
Entry
::
InvalidError
unless
valid?
...
@@ -61,7 +51,7 @@ module Gitlab
...
@@ -61,7 +51,7 @@ module Gitlab
@nodes
[
symbol
].
try
(
:value
)
@nodes
[
symbol
].
try
(
:value
)
end
end
(
@allowed_nodes
||=
{}).
merge!
(
node
)
(
@allowed_nodes
||=
{}).
merge!
(
symbol
=>
factory
)
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
cc373a35
...
@@ -27,8 +27,8 @@ module Gitlab
...
@@ -27,8 +27,8 @@ module Gitlab
end
end
def
compose!
def
compose!
allowed_nodes
.
each
do
|
key
,
ent
ry
|
allowed_nodes
.
each
do
|
key
,
facto
ry
|
add_node
(
key
,
entry
)
@nodes
[
key
]
=
create_node
(
key
,
factory
.
dup
)
end
end
end
end
...
@@ -52,7 +52,7 @@ module Gitlab
...
@@ -52,7 +52,7 @@ module Gitlab
{}
{}
end
end
def
add_node
(
key
,
entry
)
def
validate!
raise
NotImplementedError
raise
NotImplementedError
end
end
...
@@ -60,7 +60,9 @@ module Gitlab
...
@@ -60,7 +60,9 @@ module Gitlab
raise
NotImplementedError
raise
NotImplementedError
end
end
def
validate!
private
def
create_node
(
key
,
factory
)
raise
NotImplementedError
raise
NotImplementedError
end
end
end
end
...
...
lib/gitlab/ci/config/node/factory.rb
0 → 100644
View file @
cc373a35
module
Gitlab
module
Ci
class
Config
module
Node
##
# Factory class responsible for fabricating node entry objects.
#
# It uses Fluent Interface pattern to set all necessary attributes.
#
class
Factory
class
InvalidFactory
<
StandardError
;
end
def
initialize
(
entry_class
)
@entry_class
=
entry_class
@attributes
=
{}
end
def
with_value
(
value
)
@attributes
[
:value
]
=
value
self
end
def
with_description
(
description
)
@attributes
[
:description
]
=
description
self
end
def
null_node
@entry_class
=
Node
::
Null
self
end
def
create!
raise
InvalidFactory
unless
@attributes
.
has_key?
(
:value
)
@entry_class
.
new
(
@attributes
[
:value
]).
tap
do
|
entry
|
entry
.
description
=
@attributes
[
:description
]
end
end
end
end
end
end
end
spec/lib/gitlab/ci/config/node/factory_spec.rb
0 → 100644
View file @
cc373a35
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Factory
do
describe
'#create!'
do
let
(
:factory
)
{
described_class
.
new
(
entry_class
)
}
let
(
:entry_class
)
{
Gitlab
::
Ci
::
Config
::
Node
::
Script
}
context
'when value setting value'
do
it
'creates entry with valid value'
do
entry
=
factory
.
with_value
([
'ls'
,
'pwd'
])
.
create!
expect
(
entry
.
value
).
to
eq
"ls
\n
pwd"
end
context
'when setting description'
do
it
'creates entry with description'
do
entry
=
factory
.
with_value
([
'ls'
,
'pwd'
])
.
with_description
(
'test description'
)
.
create!
expect
(
entry
.
value
).
to
eq
"ls
\n
pwd"
expect
(
entry
.
description
).
to
eq
'test description'
end
end
end
context
'when not setting value'
do
it
'raises error'
do
expect
{
factory
.
create!
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Factory
::
InvalidFactory
)
end
end
context
'when creating a null entry'
do
it
'creates a null entry'
do
entry
=
factory
.
with_value
(
nil
)
.
null_node
.
create!
expect
(
entry
).
to
be_an_instance_of
Gitlab
::
Ci
::
Config
::
Node
::
Null
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment