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
Boxiang Sun
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
private
def
add_node
(
key
,
metadata
)
entry
=
create_entry
(
key
,
metadata
[
:class
])
entry
.
description
=
metadata
[
:description
]
@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
def
create_node
(
key
,
factory
)
factory
.
with_value
(
@value
[
key
])
factory
.
null_node
unless
@value
.
has_key?
(
key
)
factory
.
create!
end
class_methods
do
...
...
@@ -51,9 +42,8 @@ module Gitlab
private
def
allow_node
(
symbol
,
entry_class
,
metadata
)
node
=
{
symbol
.
to_sym
=>
{
class:
entry_class
,
description:
metadata
[
:description
]
}
}
factory
=
Node
::
Factory
.
new
(
entry_class
)
.
with_description
(
metadata
[
:description
])
define_method
(
symbol
)
do
raise
Entry
::
InvalidError
unless
valid?
...
...
@@ -61,7 +51,7 @@ module Gitlab
@nodes
[
symbol
].
try
(
:value
)
end
(
@allowed_nodes
||=
{}).
merge!
(
node
)
(
@allowed_nodes
||=
{}).
merge!
(
symbol
=>
factory
)
end
end
end
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
cc373a35
...
...
@@ -27,8 +27,8 @@ module Gitlab
end
def
compose!
allowed_nodes
.
each
do
|
key
,
ent
ry
|
add_node
(
key
,
entry
)
allowed_nodes
.
each
do
|
key
,
facto
ry
|
@nodes
[
key
]
=
create_node
(
key
,
factory
.
dup
)
end
end
...
...
@@ -52,7 +52,7 @@ module Gitlab
{}
end
def
add_node
(
key
,
entry
)
def
validate!
raise
NotImplementedError
end
...
...
@@ -60,7 +60,9 @@ module Gitlab
raise
NotImplementedError
end
def
validate!
private
def
create_node
(
key
,
factory
)
raise
NotImplementedError
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