Class: Burner::Library::Value::Nest

Inherits:
JobWithRegister show all
Defined in:
lib/burner/library/value/nest.rb

Overview

This job will nest the current value within a new outer hash. The specified key passed in will be the corresponding new hash key entry for the existing value.

Expected Payload input: anything. Payload output: hash.

Constant Summary collapse

DEFAULT_KEY =
'key'

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(key: DEFAULT_KEY, name: '', register: Burner::DEFAULT_REGISTER) ⇒ Nest

Returns a new instance of Nest.



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

def initialize(key: DEFAULT_KEY, name: '', register: Burner::DEFAULT_REGISTER)
  super(name: name, register: register)

  @key = key.to_s

  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



21
22
23
# File 'lib/burner/library/value/nest.rb', line 21

def key
  @key
end

Instance Method Details

#perform(_output, payload) ⇒ Object



31
32
33
# File 'lib/burner/library/value/nest.rb', line 31

def perform(_output, payload)
  payload[register] = { key => payload[register] }
end