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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
0d7d7c10
Commit
0d7d7c10
authored
Aug 24, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use aspect-oriented design in CI/CD config entries
parent
5ced2d8d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
37 deletions
+36
-37
lib/gitlab/ci/config/entry/configurable.rb
lib/gitlab/ci/config/entry/configurable.rb
+2
-1
lib/gitlab/ci/config/entry/node.rb
lib/gitlab/ci/config/entry/node.rb
+6
-5
lib/gitlab/ci/config/entry/validatable.rb
lib/gitlab/ci/config/entry/validatable.rb
+11
-0
lib/gitlab/ci/config/entry/validator.rb
lib/gitlab/ci/config/entry/validator.rb
+1
-1
spec/lib/gitlab/ci/config/entry/configurable_spec.rb
spec/lib/gitlab/ci/config/entry/configurable_spec.rb
+11
-25
spec/lib/gitlab/ci/config/entry/validatable_spec.rb
spec/lib/gitlab/ci/config/entry/validatable_spec.rb
+5
-5
No files found.
lib/gitlab/ci/config/entry/configurable.rb
View file @
0d7d7c10
...
...
@@ -15,9 +15,10 @@ module Gitlab
#
module
Configurable
extend
ActiveSupport
::
Concern
include
Validatable
included
do
include
Validatable
validations
do
validates
:config
,
type:
Hash
end
...
...
lib/gitlab/ci/config/entry/node.rb
View file @
0d7d7c10
...
...
@@ -16,8 +16,9 @@ module Gitlab
@metadata
=
metadata
@entries
=
{}
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
(
:new
)
self
.
class
.
aspects
.
to_a
.
each
do
|
aspect
|
instance_exec
(
&
aspect
)
end
end
def
[]
(
key
)
...
...
@@ -47,7 +48,7 @@ module Gitlab
end
def
errors
@validator
.
messages
+
descendants
.
flat_map
(
&
:errors
)
[]
end
def
value
...
...
@@ -79,8 +80,8 @@ module Gitlab
def
self
.
default
end
def
self
.
validator
Validator
def
self
.
aspects
@aspects
||=
[]
end
end
end
...
...
lib/gitlab/ci/config/entry/validatable.rb
View file @
0d7d7c10
...
...
@@ -5,6 +5,17 @@ module Gitlab
module
Validatable
extend
ActiveSupport
::
Concern
def
self
.
included
(
node
)
node
.
aspects
.
append
->
do
@validator
=
self
.
class
.
validator
.
new
(
self
)
@validator
.
validate
(
:new
)
end
end
def
errors
@validator
.
messages
+
descendants
.
flat_map
(
&
:errors
)
end
class_methods
do
def
validator
@validator
||=
Class
.
new
(
Entry
::
Validator
).
tap
do
|
validator
|
...
...
lib/gitlab/ci/config/entry/validator.rb
View file @
0d7d7c10
...
...
@@ -30,7 +30,7 @@ module Gitlab
def
key_name
if
key
.
blank?
@entry
.
class
.
name
.
demodulize
.
underscore
.
humanize
@entry
.
class
.
name
.
to_s
.
demodulize
.
underscore
.
humanize
else
key
end
...
...
spec/lib/gitlab/ci/config/entry/configurable_spec.rb
View file @
0d7d7c10
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Configurable
do
let
(
:entry
)
{
Class
.
new
}
before
do
en
try
.
include
(
described_class
)
let
(
:entry
)
do
Class
.
new
(
Gitlab
::
Ci
::
Config
::
Entry
::
Node
)
do
include
Gitlab
::
Ci
::
Config
::
Entry
::
Configurable
en
d
end
describe
'validations'
do
let
(
:validator
)
{
entry
.
validator
.
new
(
instance
)
}
before
do
entry
.
class_eval
do
attr_reader
:config
context
'when entry is a hash'
do
let
(
:instance
)
{
entry
.
new
(
key:
'value'
)
}
def
initialize
(
config
)
@config
=
config
end
it
'correctly validates an instance'
do
expect
(
instance
).
to
be_valid
end
validator
.
validate
end
context
'when entry
validator is invalid
'
do
context
'when entry
is not a hash
'
do
let
(
:instance
)
{
entry
.
new
(
'ls'
)
}
it
'returns invalid validator'
do
expect
(
validator
).
to
be_invalid
end
end
context
'when entry instance is valid'
do
let
(
:instance
)
{
entry
.
new
(
key:
'value'
)
}
it
'returns valid validator'
do
expect
(
validator
).
to
be_valid
it
'invalidates the instance'
do
expect
(
instance
).
not_to
be_valid
end
end
end
...
...
spec/lib/gitlab/ci/config/entry/validatable_spec.rb
View file @
0d7d7c10
require
'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Validatable
do
let
(
:entry
)
{
Class
.
new
}
before
do
en
try
.
include
(
described_class
)
let
(
:entry
)
do
Class
.
new
(
Gitlab
::
Ci
::
Config
::
Entry
::
Node
)
do
include
Gitlab
::
Ci
::
Config
::
Entry
::
Validatable
en
d
end
describe
'.validator'
do
...
...
@@ -28,7 +28,7 @@ describe Gitlab::Ci::Config::Entry::Validatable do
end
context
'when validating entry instance'
do
let
(
:entry_instance
)
{
entry
.
new
}
let
(
:entry_instance
)
{
entry
.
new
(
'something'
)
}
context
'when attribute is valid'
do
before
do
...
...
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