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
a2a3c4eb
Commit
a2a3c4eb
authored
Sep 05, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify classes and exceptions of extendable config
parent
50936088
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
46 deletions
+46
-46
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+2
-2
lib/gitlab/ci/config/extendable.rb
lib/gitlab/ci/config/extendable.rb
+27
-0
lib/gitlab/ci/config/extendable/collection.rb
lib/gitlab/ci/config/extendable/collection.rb
+0
-32
lib/gitlab/ci/config/extendable/entry.rb
lib/gitlab/ci/config/extendable/entry.rb
+9
-5
spec/lib/gitlab/ci/config/extendable/entry_spec.rb
spec/lib/gitlab/ci/config/extendable/entry_spec.rb
+3
-2
spec/lib/gitlab/ci/config/extendable_spec.rb
spec/lib/gitlab/ci/config/extendable_spec.rb
+5
-5
No files found.
lib/gitlab/ci/config.rb
View file @
a2a3c4eb
...
@@ -9,13 +9,13 @@ module Gitlab
...
@@ -9,13 +9,13 @@ module Gitlab
ConfigError
=
Class
.
new
(
StandardError
)
ConfigError
=
Class
.
new
(
StandardError
)
def
initialize
(
config
,
opts
=
{})
def
initialize
(
config
,
opts
=
{})
@config
=
Extendable
::
Collection
@config
=
Config
::
Extendable
.
new
(
build_config
(
config
,
opts
))
.
new
(
build_config
(
config
,
opts
))
.
to_hash
.
to_hash
@global
=
Entry
::
Global
.
new
(
@config
)
@global
=
Entry
::
Global
.
new
(
@config
)
@global
.
compose!
@global
.
compose!
rescue
Loader
::
FormatError
,
Extendable
::
Collection
::
ExtensionError
=>
e
rescue
Loader
::
FormatError
,
Extendable
::
ExtensionError
=>
e
raise
Config
::
ConfigError
,
e
.
message
raise
Config
::
ConfigError
,
e
.
message
end
end
...
...
lib/gitlab/ci/config/extendable.rb
0 → 100644
View file @
a2a3c4eb
module
Gitlab
module
Ci
class
Config
class
Extendable
include
Enumerable
ExtensionError
=
Class
.
new
(
StandardError
)
def
initialize
(
hash
)
@hash
=
hash
.
to_h
.
deep_dup
each
{
|
entry
|
entry
.
extend!
if
entry
.
extensible?
}
end
def
each
@hash
.
each_key
do
|
key
|
yield
Extendable
::
Entry
.
new
(
key
,
@hash
)
end
end
def
to_hash
@hash
.
to_h
end
end
end
end
end
lib/gitlab/ci/config/extendable/collection.rb
deleted
100644 → 0
View file @
50936088
module
Gitlab
module
Ci
class
Config
module
Extendable
class
Collection
include
Enumerable
ExtensionError
=
Class
.
new
(
StandardError
)
InvalidExtensionError
=
Class
.
new
(
ExtensionError
)
CircularDependencyError
=
Class
.
new
(
ExtensionError
)
NestingTooDeepError
=
Class
.
new
(
ExtensionError
)
def
initialize
(
hash
)
@hash
=
hash
.
to_h
.
deep_dup
each
{
|
entry
|
entry
.
extend!
if
entry
.
extensible?
}
end
def
each
@hash
.
each_key
do
|
key
|
yield
Extendable
::
Entry
.
new
(
key
,
@hash
)
end
end
def
to_hash
@hash
.
to_h
end
end
end
end
end
end
lib/gitlab/ci/config/extendable/entry.rb
View file @
a2a3c4eb
module
Gitlab
module
Gitlab
module
Ci
module
Ci
class
Config
class
Config
module
Extendable
class
Extendable
class
Entry
class
Entry
MAX_NESTING_LEVELS
=
10
MAX_NESTING_LEVELS
=
10
InvalidExtensionError
=
Class
.
new
(
Extendable
::
ExtensionError
)
CircularDependencyError
=
Class
.
new
(
Extendable
::
ExtensionError
)
NestingTooDeepError
=
Class
.
new
(
Extendable
::
ExtensionError
)
attr_reader
:key
attr_reader
:key
def
initialize
(
key
,
context
,
parent
=
nil
)
def
initialize
(
key
,
context
,
parent
=
nil
)
...
@@ -43,22 +47,22 @@ module Gitlab
...
@@ -43,22 +47,22 @@ module Gitlab
return
value
unless
extensible?
return
value
unless
extensible?
if
unknown_extension?
if
unknown_extension?
raise
E
xtendable
::
Collection
::
InvalidExtensionError
,
raise
E
ntry
::
InvalidExtensionError
,
"Unknown extends key in extended `
#{
key
}
`!"
"Unknown extends key in extended `
#{
key
}
`!"
end
end
if
invalid_base?
if
invalid_base?
raise
E
xtendable
::
Collection
::
InvalidExtensionError
,
raise
E
ntry
::
InvalidExtensionError
,
"Invalid base hash in extended `
#{
key
}
`!"
"Invalid base hash in extended `
#{
key
}
`!"
end
end
if
nesting_too_deep?
if
nesting_too_deep?
raise
E
xtendable
::
Collection
::
NestingTooDeepError
,
raise
E
ntry
::
NestingTooDeepError
,
"`extends` nesting too deep in `
#{
key
}
`!"
"`extends` nesting too deep in `
#{
key
}
`!"
end
end
if
circular_dependency?
if
circular_dependency?
raise
E
xtendable
::
Collection
::
CircularDependencyError
,
raise
E
ntry
::
CircularDependencyError
,
"Circular dependency detected in extended `
#{
key
}
`!"
"Circular dependency detected in extended `
#{
key
}
`!"
end
end
...
...
spec/lib/gitlab/ci/config/extendable/entry_spec.rb
View file @
a2a3c4eb
...
@@ -198,7 +198,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
...
@@ -198,7 +198,8 @@ describe Gitlab::Ci::Config::Extendable::Entry do
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
.
extend!
}
expect
{
subject
.
extend!
}
.
to
raise_error
(
StandardError
,
/Circular dependency detected/
)
.
to
raise_error
(
described_class
::
CircularDependencyError
,
/Circular dependency detected/
)
end
end
end
end
...
@@ -217,7 +218,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do
...
@@ -217,7 +218,7 @@ describe Gitlab::Ci::Config::Extendable::Entry do
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
.
extend!
}
expect
{
subject
.
extend!
}
.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Extendable
::
Collection
::
NestingTooDeepError
)
.
to
raise_error
(
described_class
::
NestingTooDeepError
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/config/extendable
/collection
_spec.rb
→
spec/lib/gitlab/ci/config/extendable_spec.rb
View file @
a2a3c4eb
require
'fast_spec_helper'
require
'fast_spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Extendable
::
Collection
do
describe
Gitlab
::
Ci
::
Config
::
Extendable
do
subject
{
described_class
.
new
(
hash
)
}
subject
{
described_class
.
new
(
hash
)
}
describe
'#each'
do
describe
'#each'
do
...
@@ -147,7 +147,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
...
@@ -147,7 +147,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
it
'raises an error about circular dependency'
do
it
'raises an error about circular dependency'
do
expect
{
subject
.
to_hash
}
expect
{
subject
.
to_hash
}
.
to
raise_error
(
described_class
::
CircularDependencyError
)
.
to
raise_error
(
described_class
::
Entry
::
CircularDependencyError
)
end
end
end
end
...
@@ -164,7 +164,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
...
@@ -164,7 +164,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
it
'raises an error about circular dependency'
do
it
'raises an error about circular dependency'
do
expect
{
subject
.
to_hash
}
expect
{
subject
.
to_hash
}
.
to
raise_error
(
described_class
::
CircularDependencyError
)
.
to
raise_error
(
described_class
::
Entry
::
CircularDependencyError
)
end
end
end
end
...
@@ -175,7 +175,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
...
@@ -175,7 +175,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
it
'raises an error about invalid extension'
do
it
'raises an error about invalid extension'
do
expect
{
subject
.
to_hash
}
expect
{
subject
.
to_hash
}
.
to
raise_error
(
described_class
::
InvalidExtensionError
)
.
to
raise_error
(
described_class
::
Entry
::
InvalidExtensionError
)
end
end
end
end
...
@@ -194,7 +194,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
...
@@ -194,7 +194,7 @@ describe Gitlab::Ci::Config::Extendable::Collection do
it
'raises an error about invalid base'
do
it
'raises an error about invalid base'
do
expect
{
subject
.
to_hash
}
expect
{
subject
.
to_hash
}
.
to
raise_error
(
described_class
::
InvalidExtensionError
)
.
to
raise_error
(
described_class
::
Entry
::
InvalidExtensionError
)
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