10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/cloudrail_si/servicecode/commands/Push.rb', line 10
def execute(environment, parameters)
Helper.assert(parameters.length >= 2 &&
Helper.is_var_address(parameters[0]))
target_var = parameters[0]
value = Helper.resolve(environment, parameters[1])
target_var_parts = environment.decode_variable_address(target_var)
(2..parameters.length - 1).each do |i|
target_var_parts.push(Helper.resolve(environment, parameters[i]))
end
container = environment.get_variable(target_var_parts)
if (Helper.is_array(container))
container.push(value)
elsif (Helper.is_object(container))
container[container.length] = value
elsif (Helper.is_string(container))
environment.set_variable(target_var_parts, container.concat(value.to_string()))
else
raise Errors::InternalError.new('Push only works for lists, objects and strings')
end
end
|