Class: Burner::Library::Collection::Unshift

Inherits:
JobWithRegister show all
Defined in:
lib/burner/library/collection/unshift.rb

Overview

Adds the values of the from_registers to the to_register array. All existing elements in the register array will be shifted upwards.

Expected Payload input: Array containing names of registers whose values to prepend. Payload output: An array with the from_registers’ payload added to the beginning.

Constant Summary

Constants inherited from JobWithRegister

JobWithRegister::BLANK

Instance Attribute Summary collapse

Attributes inherited from JobWithRegister

#register

Attributes inherited from Job

#name

Instance Method Summary collapse

Methods included from Util::Arrayable

#array

Constructor Details

#initialize(from_registers: [], name: '', register: DEFAULT_REGISTER) ⇒ Unshift

Returns a new instance of Unshift.



23
24
25
26
27
28
29
# File 'lib/burner/library/collection/unshift.rb', line 23

def initialize(from_registers: [], name: '', register: DEFAULT_REGISTER)
  super(name: name, register: register)

  @from_registers = Array(from_registers)

  freeze
end

Instance Attribute Details

#from_registersObject (readonly)

Returns the value of attribute from_registers.



21
22
23
# File 'lib/burner/library/collection/unshift.rb', line 21

def from_registers
  @from_registers
end

Instance Method Details

#perform(output, payload) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/burner/library/collection/unshift.rb', line 31

def perform(output, payload)
  output.detail("Prepending registers: '#{from_registers}' to: '#{register}'")

  payload_register = array(payload[register])

  from_registers.each do |from_register|
    from_register_value = payload[from_register]

    payload_register.unshift(from_register_value)
  end
end