Module: Dataflow::Nodes::Mixin::AddInternalTimestamp

Included in:
SnapshotNode, UpsertNode
Defined in:
lib/dataflow/nodes/mixin/add_internal_timestamp.rb

Overview

Add an internal updated_at timestamp to the records.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



7
8
9
10
11
12
# File 'lib/dataflow/nodes/mixin/add_internal_timestamp.rb', line 7

def self.included(base)
  base.class_eval do
    field :use_internal_timestamp, type: Boolean, default: true
    field :internal_timestamp_key, type: String, default: '_mojaco_updated_at'
  end
end

Instance Method Details

#add_internal_timestamp(records:) ⇒ Object

Add an internal updated_at timestamp to the records



15
16
17
18
19
20
21
22
23
# File 'lib/dataflow/nodes/mixin/add_internal_timestamp.rb', line 15

def add_internal_timestamp(records:)
  return unless use_internal_timestamp
  return unless internal_timestamp_key.present?

  updated_at = Time.now
  records.each do |record|
    record[internal_timestamp_key] = updated_at
  end
end