Class: CloudRailSi::ServiceCode::Pull

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudrail_si/servicecode/commands/Pull.rb

Instance Method Summary collapse

Instance Method Details

#execute(environment, parameters) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cloudrail_si/servicecode/commands/Pull.rb', line 10

def execute(environment, parameters)
    Helper.assert(parameters.length >= 2 &&
                  Helper.is_var_address(parameters[0]) &&
                  Helper.is_var_address(parameters[1]))
    target_var = parameters[0]
    container_var = parameters[1]
    container_var_parts = environment.decode_variable_address(container_var)
    (2..parameters.length - 1).each do |i|
        container_var_parts.push(Helper.resolve(environment, parameters[i]))
    end
    container = environment.get_variable(container_var_parts)

    if (Helper.is_array(container))
        entry = container.pop()
    elsif (Helper.is_string(container))
        entry = container[-1]
        environment.set_variable(container_var_parts, container)
    else
        raise Errors::InternalError.new('Pull only works for lists and strings')
    end
    environment.set_variable(target_var, entry)
end

#get_identifierObject



6
7
8
# File 'lib/cloudrail_si/servicecode/commands/Pull.rb', line 6

def get_identifier
    'pull'
end