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
2ff8668b
Commit
2ff8668b
authored
Nov 12, 2020
by
Marius Bobin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement maintainer feedback
Refactor the code for readability and add a missing test case
parent
78845b8f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
10 deletions
+25
-10
lib/expand_variables.rb
lib/expand_variables.rb
+18
-10
spec/lib/expand_variables_spec.rb
spec/lib/expand_variables_spec.rb
+7
-0
No files found.
lib/expand_variables.rb
View file @
2ff8668b
...
@@ -5,27 +5,35 @@ module ExpandVariables
...
@@ -5,27 +5,35 @@ module ExpandVariables
class
<<
self
class
<<
self
def
expand
(
value
,
variables
)
def
expand
(
value
,
variables
)
variables_hash
=
nil
replace_with
(
value
,
variables
)
do
|
vars_hash
,
last_match
|
match_or_blank_value
(
vars_hash
,
last_match
)
value
.
gsub
(
VARIABLES_REGEXP
)
do
variables_hash
||=
transform_variables
(
variables
)
variables_hash
[
Regexp
.
last_match
(
1
)
||
Regexp
.
last_match
(
2
)]
end
end
end
end
def
expand_existing
(
value
,
variables
)
def
expand_existing
(
value
,
variables
)
replace_with
(
value
,
variables
)
do
|
vars_hash
,
last_match
|
match_or_original_value
(
vars_hash
,
last_match
)
end
end
private
def
replace_with
(
value
,
variables
)
variables_hash
=
nil
variables_hash
=
nil
value
.
gsub
(
VARIABLES_REGEXP
)
do
value
.
gsub
(
VARIABLES_REGEXP
)
do
variables_hash
||=
transform_variables
(
variables
)
variables_hash
||=
transform_variables
(
variables
)
variables_hash
.
fetch
(
yield
(
variables_hash
,
Regexp
.
last_match
)
Regexp
.
last_match
(
1
)
||
Regexp
.
last_match
(
2
),
Regexp
.
last_match
(
0
)
)
end
end
end
end
private
def
match_or_blank_value
(
variables
,
last_match
)
variables
[
last_match
[
1
]
||
last_match
[
2
]]
end
def
match_or_original_value
(
variables
,
last_match
)
match_or_blank_value
(
variables
,
last_match
)
||
last_match
[
0
]
end
def
transform_variables
(
variables
)
def
transform_variables
(
variables
)
# Lazily initialise variables
# Lazily initialise variables
...
...
spec/lib/expand_variables_spec.rb
View file @
2ff8668b
...
@@ -113,6 +113,13 @@ RSpec.describe ExpandVariables do
...
@@ -113,6 +113,13 @@ RSpec.describe ExpandVariables do
variables:
[
variables:
[
{
key:
'variable'
,
value:
'value'
}
{
key:
'variable'
,
value:
'value'
}
]
]
},
"complex expansions with missing variable for Windows"
:
{
value:
'key%variable%%variable2%'
,
result:
'keyvalue'
,
variables:
[
{
key:
'variable'
,
value:
'value'
}
]
}
}
}
}
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