Class: Burner::Library::Collection::Unshift
- Inherits:
-
JobWithRegister
- Object
- Job
- JobWithRegister
- Burner::Library::Collection::Unshift
- 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
Instance Attribute Summary collapse
-
#from_registers ⇒ Object
readonly
Returns the value of attribute from_registers.
Attributes inherited from JobWithRegister
Attributes inherited from Job
Instance Method Summary collapse
-
#initialize(from_registers: [], name: '', register: DEFAULT_REGISTER) ⇒ Unshift
constructor
A new instance of Unshift.
- #perform(output, payload) ⇒ Object
Methods included from Util::Arrayable
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_registers ⇒ Object (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 |