Class: Pyper::Pipes::RemoveFields

Inherits:
Object
  • Object
show all
Defined in:
lib/pyper/pipes/remove_fields.rb

Overview

A generic pipe to remove fields from a pipeline

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fields_to_remove) ⇒ RemoveFields

Returns a new instance of RemoveFields.

Parameters:

  • fields_to_remove (Array)

    fields to be removed from pipe



8
9
10
# File 'lib/pyper/pipes/remove_fields.rb', line 8

def initialize(fields_to_remove)
  @fields_to_remove = Array.wrap(fields_to_remove)
end

Instance Attribute Details

#fields_to_removeObject (readonly)

Returns the value of attribute fields_to_remove.



5
6
7
# File 'lib/pyper/pipes/remove_fields.rb', line 5

def fields_to_remove
  @fields_to_remove
end

Instance Method Details

#pipe(attributes, status = {}) ⇒ Hash

Returns attributes with the specified fields removed.

Parameters:

  • attributes (Hash)

    The attributes from which to remove the specified fields

  • status (Hash) (defaults to: {})

    The mutable status field

Returns:

  • (Hash)

    attributes with the specified fields removed



15
16
17
18
19
20
# File 'lib/pyper/pipes/remove_fields.rb', line 15

def pipe(attributes, status = {})
  attributes = attributes.dup
  fields_to_remove.each { |field| attributes.delete(field) }

  attributes
end