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
Hide 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
...
@@ -51,7 +51,7 @@ module Gitlab
def
helpers
(
*
nodes
)
def
helpers
(
*
nodes
)
nodes
.
each
do
|
symbol
|
nodes
.
each
do
|
symbol
|
define_method
(
"
#{
symbol
}
_defined?"
)
do
define_method
(
"
#{
symbol
}
_defined?"
)
do
@entries
[
symbol
].
try
(
:defined?
)
@entries
[
symbol
].
specified?
end
end
define_method
(
"
#{
symbol
}
_value"
)
do
define_method
(
"
#{
symbol
}
_value"
)
do
...
...
lib/gitlab/ci/config/node/entry.rb
View file @
06641a3f
...
@@ -66,14 +66,14 @@ module Gitlab
...
@@ -66,14 +66,14 @@ module Gitlab
@config
@config
else
else
meaningful
=
@entries
.
select
do
|
_key
,
value
|
meaningful
=
@entries
.
select
do
|
_key
,
value
|
value
.
defin
ed?
&&
value
.
relevant?
value
.
specifi
ed?
&&
value
.
relevant?
end
end
Hash
[
meaningful
.
map
{
|
key
,
entry
|
[
key
,
entry
.
value
]
}]
Hash
[
meaningful
.
map
{
|
key
,
entry
|
[
key
,
entry
.
value
]
}]
end
end
end
end
def
defin
ed?
def
specifi
ed?
true
true
end
end
...
...
lib/gitlab/ci/config/node/factory.rb
View file @
06641a3f
...
@@ -40,11 +40,21 @@ module Gitlab
...
@@ -40,11 +40,21 @@ module Gitlab
# See issue #18775.
# See issue #18775.
#
#
if
@value
.
nil?
if
@value
.
nil?
Node
::
Undefined
.
new
(
@node
,
attributes
)
Node
::
Undefined
.
new
(
fabricate_undefined
(
attributes
)
)
else
else
@node
.
new
(
@value
,
attributes
)
@node
.
new
(
@value
,
attributes
)
end
end
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
end
end
end
...
...
lib/gitlab/ci/config/node/null.rb
View file @
06641a3f
...
@@ -8,10 +8,6 @@ module Gitlab
...
@@ -8,10 +8,6 @@ module Gitlab
# Implements the Null Object pattern.
# Implements the Null Object pattern.
#
#
class
Null
<
Entry
class
Null
<
Entry
def
initialize
(
config
=
nil
,
**
attributes
)
super
end
def
value
def
value
nil
nil
end
end
...
@@ -23,6 +19,14 @@ module Gitlab
...
@@ -23,6 +19,14 @@ module Gitlab
def
errors
def
errors
[]
[]
end
end
def
specified?
false
end
def
relevant?
false
end
end
end
end
end
end
end
...
...
lib/gitlab/ci/config/node/undefined.rb
View file @
06641a3f
...
@@ -3,66 +3,19 @@ module Gitlab
...
@@ -3,66 +3,19 @@ module Gitlab
class
Config
class
Config
module
Node
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
# It decorates original entry adding method that idicates it is
# if original entry has a default value. If there is default value
# unspecified.
# some methods are delegated to it.
#
#
#
class
Undefined
<
SimpleDelegator
class
Undefined
<
Entry
def
initialize
(
entry
)
include
Validatable
delegate
:valid?
,
:errors
,
:value
,
to: :@strategy
validations
do
validates
:config
,
type:
Class
end
def
initialize
(
node
,
**
attributes
)
super
super
@strategy
=
create_strategy
(
node
,
node
.
default
)
end
end
def
defin
ed?
def
specifi
ed?
false
false
end
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
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
...
@@ -233,9 +233,9 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
end
end
describe
'#
defin
ed?'
do
describe
'#
specifi
ed?'
do
it
'is concrete entry that is defined'
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
end
end
end
spec/lib/gitlab/ci/config/node/null_spec.rb
View file @
06641a3f
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Null
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Null
do
let
(
:null
)
{
described_class
.
new
}
let
(
:null
)
{
described_class
.
new
(
nil
)
}
describe
'#leaf?'
do
describe
'#leaf?'
do
it
'is leaf node'
do
it
'is leaf node'
do
...
@@ -26,4 +26,16 @@ describe Gitlab::Ci::Config::Node::Null do
...
@@ -26,4 +26,16 @@ describe Gitlab::Ci::Config::Node::Null do
expect
(
null
.
value
).
to
eq
nil
expect
(
null
.
value
).
to
eq
nil
end
end
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
end
spec/lib/gitlab/ci/config/node/undefined_spec.rb
View file @
06641a3f
...
@@ -4,66 +4,29 @@ describe Gitlab::Ci::Config::Node::Undefined do
...
@@ -4,66 +4,29 @@ describe Gitlab::Ci::Config::Node::Undefined do
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:undefined
)
{
described_class
.
new
(
entry
)
}
let
(
:entry
)
{
spy
(
'Entry'
)
}
let
(
:entry
)
{
spy
(
'Entry'
)
}
context
'when entry does not have a default value'
do
describe
'#valid?'
do
before
{
allow
(
entry
).
to
receive
(
:default
).
and_return
(
nil
)
}
it
'delegates method to entry'
do
expect
(
undefined
.
valid
).
to
eq
entry
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
end
end
describe
'#errors'
do
it
'is does not contain errors'
do
expect
(
undefined
.
errors
).
to
be_empty
end
end
describe
'#value'
do
it
'returns nil'
do
expect
(
undefined
.
value
).
to
eq
nil
end
end
end
end
end
context
'when entry has a default value'
do
describe
'#errors'
do
before
do
it
'delegates method to entry'
do
allow
(
entry
).
to
receive
(
:default
).
and_return
(
'some value'
)
expect
(
undefined
.
errors
).
to
eq
entry
allow
(
entry
).
to
receive
(
:value
).
and_return
(
'some value'
)
end
end
end
describe
'#value'
do
describe
'#value'
do
it
'returns default value for entry'
do
it
'delegates method to entry'
do
expect
(
undefined
.
value
).
to
eq
'some value'
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
end
end
describe
'#undefined?'
do
describe
'#specified?'
do
it
'is not a defined entry'
do
it
'is always false'
do
expect
(
undefined
.
defined?
).
to
be
false
allow
(
entry
).
to
receive
(
:specified?
).
and_return
(
true
)
expect
(
undefined
.
specified?
).
to
be
false
end
end
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