class Burner::Library::Collection::OnlyKeys

This job knows how to take an array of objects and limit it to a specific set of keys. The keys are pulled from another register which helps make it dynamic (you can load up this other register with a dynamic list of keys at run-time.)

Expected Payload input: array of objects. Payload output: An array of objects.

Public Instance Methods

perform(output, payload) click to toggle source
# File lib/burner/library/collection/only_keys.rb, line 20
def perform(output, payload)
  objects = array(payload[register])
  count   = objects.length
  keys    = array(payload[keys_register])

  output.detail("Dynamically limiting #{count} object(s) with key(s): #{keys.join(', ')}")

  payload[register] = objects.map { |object| transform(object, keys) }
end

Private Instance Methods

transform(object, keys) click to toggle source
# File lib/burner/library/collection/only_keys.rb, line 32
def transform(object, keys)
  keys.each_with_object({}) do |key, memo|
    value = resolver.get(object, key)

    resolver.set(memo, key, value)
  end
end