Module: Peplum::Application::Payload

Defined in:
lib/peplum/application/payload.rb

Defined Under Namespace

Classes: Error

Instance Method Summary collapse

Instance Method Details

#merge(data) ⇒ Object

Merge result ‘data` for reporting.

By default provides a generic implementation that merges the values of ‘Hash`es and `Array`s. If `String`s or `Numeric`s are contained, the Array is returned as is.

Parameters:

  • data (Array)

    Report data from workers.

Returns:

  • (Object)

    Merged results.

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/peplum/application/payload.rb', line 40

def merge( data )
  case data.first
  when Hash
      f = data.pop
      data.each do |d|

        if !f.is_a? Hash
          fail Error::ImplementationMissing, 'Missing implementation: Item not a Hash!'
        end

        f.merge! d
      end
      f

  when Array
    data.flatten

  when String, Numeric
    data

  else
    fail Error::ImplementationMissing, 'Missing implementation.'
  end
end

#run(objects, options) ⇒ Object

This method is abstract.

Run payload against ‘objects` based on given `options`

Parameters:

  • objects (Array)

    Objects that this worker should process.

  • options (Hash, NilClass)

    Worker options.



17
18
19
# File 'lib/peplum/application/payload.rb', line 17

def run( objects, options )
  fail Error::ImplementationMissing, 'Missing implementation.'
end

#split(objects, groups_of) ⇒ Array<Array<Object>>

Distribute ‘objects` into `groups_of` amount of groups, one for each worker.

Parameters:

  • objects (Array)

    All objects that need to be processed.

  • groups_of (Integer)

    Amount of object groups that should be generated.

Returns:

  • (Array<Array<Object>>)

    ‘objects` split in `chunks` amount of groups.



27
28
29
# File 'lib/peplum/application/payload.rb', line 27

def split( objects, groups_of )
  objects.chunk groups_of
end