Do not use keyword args to pass expression variables
This commit is contained in:
parent
3938d1c3a0
commit
886988c9e1
6 changed files with 13 additions and 6 deletions
|
@ -11,7 +11,7 @@ module Gitlab
|
||||||
@right = right
|
@right = right
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(**variables)
|
def evaluate(variables = {})
|
||||||
@left.evaluate(variables) == @right.evaluate(variables)
|
@left.evaluate(variables) == @right.evaluate(variables)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Gitlab
|
||||||
@value = nil
|
@value = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(**_)
|
def evaluate(variables = {})
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ module Gitlab
|
||||||
@value = value
|
@value = value
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(**_)
|
def evaluate(variables = {})
|
||||||
@value.to_s
|
@value.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -10,8 +10,8 @@ module Gitlab
|
||||||
@name = name
|
@name = name
|
||||||
end
|
end
|
||||||
|
|
||||||
def evaluate(**variables)
|
def evaluate(variables = {})
|
||||||
variables[@name.to_sym]
|
HashWithIndifferentAccess.new(variables).fetch(@name, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.build(string)
|
def self.build(string)
|
||||||
|
|
|
@ -18,7 +18,7 @@ module Gitlab
|
||||||
@lexer = Expression::Lexer.new(statement)
|
@lexer = Expression::Lexer.new(statement)
|
||||||
|
|
||||||
@variables = pipeline.variables.map do |variable|
|
@variables = pipeline.variables.map do |variable|
|
||||||
[variable.key.to_sym, variable.value]
|
[variable.key, variable.value]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,13 @@ describe Gitlab::Ci::Pipeline::Expression::Lexeme::Variable do
|
||||||
.to eq 'my variable'
|
.to eq 'my variable'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'allows to use a string as a variable key too' do
|
||||||
|
variable = described_class.new('VARIABLE')
|
||||||
|
|
||||||
|
expect(variable.evaluate('VARIABLE' => 'my variable'))
|
||||||
|
.to eq 'my variable'
|
||||||
|
end
|
||||||
|
|
||||||
it 'returns nil if it is not defined' do
|
it 'returns nil if it is not defined' do
|
||||||
variable = described_class.new('VARIABLE')
|
variable = described_class.new('VARIABLE')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue