Class: Realize::Type::Array

Inherits:
Base
  • Object
show all
Includes:
Arrays
Defined in:
lib/realize/type/array.rb

Overview

Ensure the value is an array by calling Kernel#Array on the value. If the value is a hash then it will ensure the hash data structure is preserved and placed within the array. Normally calling Array(hash) would yield an array of key-value pair arrays. For our pipeline we generally treat hashes as “record-like” objects, so we need to ensure we keep it in tact.

This does not mean other data types do not suffer from Kernel#Array converting it to something unexpected. For example, passing in a Time object would yield an array of parts:

Array(Time.now) => [2, 59, 10, 21, 11, 2020, 6, 326, false, "CST"]

See: ruby-doc.org/core-2.7.2/Kernel.html#method-i-Array for more information.

Instance Attribute Summary

Attributes inherited from Base

#nullable

Instance Method Summary collapse

Methods included from Arrays

#array

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Realize::Type::Base

Instance Method Details

#transform(_resolver, value, _time, _record) ⇒ Object



29
30
31
32
33
# File 'lib/realize/type/array.rb', line 29

def transform(_resolver, value, _time, _record)
  return nil if nullable && value.nil?

  array(value)
end