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
Tatuya Kamada
gitlab-ce
Commits
06641a3f
Commit
06641a3f
authored
Jul 12, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify undefined node definition in CI config
parent
d41d3301
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
116 deletions
+58
-116
lib/gitlab/ci/config/node/configurable.rb
lib/gitlab/ci/config/node/configurable.rb
+1
-1
lib/gitlab/ci/config/node/entry.rb
lib/gitlab/ci/config/node/entry.rb
+2
-2
lib/gitlab/ci/config/node/factory.rb
lib/gitlab/ci/config/node/factory.rb
+11
-1
lib/gitlab/ci/config/node/null.rb
lib/gitlab/ci/config/node/null.rb
+8
-4
lib/gitlab/ci/config/node/undefined.rb
lib/gitlab/ci/config/node/undefined.rb
+6
-53
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+2
-2
spec/lib/gitlab/ci/config/node/null_spec.rb
spec/lib/gitlab/ci/config/node/null_spec.rb
+13
-1
spec/lib/gitlab/ci/config/node/undefined_spec.rb
spec/lib/gitlab/ci/config/node/undefined_spec.rb
+15
-52
No files found.
lib/gitlab/ci/config/node/configurable.rb
View file @
06641a3f
...
...
@@ -51,7 +51,7 @@ module Gitlab
def
helpers
(
*
nodes
)
nodes
.
each
do
|
symbol
|
define_method
(
"
#{
symbol
}
_defined?"
)
do
@entries
[
symbol
].
try
(
:defined?
)
@entries
[
symbol
].
specified?
end
define_method
(
"
#{
symbol
}
_value"
)
do
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
06641a3f
...
...
@@ -66,14 +66,14 @@ module Gitlab
@config
else
meaningful
=
@entries
.
select
do
|
_key
,
value
|
value
.
defin
ed?
&&
value
.
relevant?
value
.
specifi
ed?
&&
value
.
relevant?
end
Hash
[
meaningful
.
map
{
|
key
,
entry
|
[
key
,
entry
.
value
]
}]
end
end
def
defin
ed?
def
specifi
ed?
true
end
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
06641a3f
...
...
@@ -40,11 +40,21 @@ module Gitlab
# See issue #18775.
#
if
@value
.
nil?
Node
::
Undefined
.
new
(
@node
,
attributes
)
Node
::
Undefined
.
new
(
fabricate_undefined
(
attributes
)
)
else
@node
.
new
(
@value
,
attributes
)
end
end
private
def
fabricate_undefined
(
attributes
)
if
@node
.
default
.
nil?
Node
::
Null
.
new
(
nil
,
attributes
)
else
@node
.
new
(
@node
.
default
,
attributes
)
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/null.rb
View file @
06641a3f
...
...
@@ -8,10 +8,6 @@ module Gitlab
# Implements the Null Object pattern.
#
class
Null
<
Entry
def
initialize
(
config
=
nil
,
**
attributes
)
super
end
def
value
nil
end
...
...
@@ -23,6 +19,14 @@ module Gitlab
def
errors
[]
end
def
specified?
false
end
def
relevant?
false
end
end
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
View file @
06641a3f
...
...
@@ -3,66 +3,19 @@ module Gitlab
class
Config
module
Node
##
# This class represents an undefined entry node.
# This class represents an undefined
and unspecified
entry node.
#
# It takes original entry class as configuration and creates an object
# if original entry has a default value. If there is default value
# some methods are delegated to it.
# It decorates original entry adding method that idicates it is
# unspecified.
#
#
class
Undefined
<
Entry
include
Validatable
delegate
:valid?
,
:errors
,
:value
,
to: :@strategy
validations
do
validates
:config
,
type:
Class
end
def
initialize
(
node
,
**
attributes
)
class
Undefined
<
SimpleDelegator
def
initialize
(
entry
)
super
@strategy
=
create_strategy
(
node
,
node
.
default
)
end
def
defin
ed?
def
specifi
ed?
false
end
private
def
create_strategy
(
node
,
default
)
if
default
.
nil?
Undefined
::
NullStrategy
.
new
else
entry
=
node
.
new
(
default
,
attributes
)
Undefined
::
DefaultStrategy
.
new
(
entry
)
end
end
class
DefaultStrategy
delegate
:valid?
,
:errors
,
:value
,
to: :@default
def
initialize
(
entry
)
@default
=
entry
end
end
class
NullStrategy
def
initialize
(
*
)
end
def
value
nil
end
def
valid?
true
end
def
errors
[]
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
06641a3f
...
...
@@ -233,9 +233,9 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
describe
'#
defin
ed?'
do
describe
'#
specifi
ed?'
do
it
'is concrete entry that is defined'
do
expect
(
global
.
defin
ed?
).
to
be
true
expect
(
global
.
specifi
ed?
).
to
be
true
end
end
end
spec/lib/gitlab/ci/config/node/null_spec.rb
View file @
06641a3f
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Null
do
let
(
:null
)
{
described_class
.
new
}
let
(
:null
)
{
described_class
.
new
(
nil
)
}
describe
'#leaf?'
do
it
'is leaf node'
do
...
...
@@ -26,4 +26,16 @@ describe Gitlab::Ci::Config::Node::Null do
expect
(
null
.
value
).
to
eq
nil
end
end
describe
'#relevant?'
do
it
'is not relevant'
do
expect
(
null
.
relevant?
).
to
eq
false
end
end
describe
'#specified?'
do
it
'is not defined'
do
expect
(
null
.
specified?
).
to
eq
false
end
end
end
spec/lib/gitlab/ci/config/node/undefined_spec.rb
View file @
06641a3f
...
...
@@ -4,66 +4,29 @@ describe Gitlab::Ci::Config::Node::Undefined do
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:entry
)
{
spy
(
'Entry'
)
}
context
'when entry does not have a default value'
do
before
{
allow
(
entry
).
to
receive
(
:default
).
and_return
(
nil
)
}
describe
'#leaf?'
do
it
'is leaf node'
do
expect
(
undefined
).
to
be_leaf
end
end
describe
'#valid?'
do
it
'is always valid
'
do
expect
(
undefined
).
to
be_valid
it
'delegates method to entry
'
do
expect
(
undefined
.
valid
).
to
eq
entry
end
end
describe
'#errors'
do
it
'is does not contain errors'
do
expect
(
undefined
.
errors
).
to
be_empty
end
it
'delegates method to entry'
do
expect
(
undefined
.
errors
).
to
eq
entry
end
describe
'#value'
do
it
'returns nil'
do
expect
(
undefined
.
value
).
to
eq
nil
end
end
end
context
'when entry has a default value'
do
before
do
allow
(
entry
).
to
receive
(
:default
).
and_return
(
'some value'
)
allow
(
entry
).
to
receive
(
:value
).
and_return
(
'some value'
)
end
describe
'#value'
do
it
'returns default value for
entry'
do
expect
(
undefined
.
value
).
to
eq
'some value'
it
'delegates method to
entry'
do
expect
(
undefined
.
value
).
to
eq
entry
end
end
describe
'#errors'
do
it
'delegates errors to default entry'
do
expect
(
entry
).
to
receive
(
:errors
)
undefined
.
errors
end
end
describe
'#valid?'
do
it
'delegates valid? to default entry'
do
expect
(
entry
).
to
receive
(
:valid?
)
undefined
.
valid?
end
end
end
describe
'#specified?'
do
it
'is always false'
do
allow
(
entry
).
to
receive
(
:specified?
).
and_return
(
true
)
describe
'#undefined?'
do
it
'is not a defined entry'
do
expect
(
undefined
.
defined?
).
to
be
false
expect
(
undefined
.
specified?
).
to
be
false
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