Welcome to mirror list, hosted at ThFree Co, Russian Federation.

bulk_operation_hashes.rb « integrations « concerns « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3f13c764ebe780450e40cbc4e18caf3b8f15943c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

# Returns hashes of attributes suitable for passing to `.insert_all` or `update_all`
module Integrations
  module BulkOperationHashes
    private

    def integration_hash(operation)
      integration
        .to_database_hash
        .merge('inherit_from_id' => integration.inherit_from_id || integration.id)
        .merge(update_timestamps(operation))
    end

    def data_fields_hash(operation)
      integration
        .data_fields
        .to_database_hash
        .merge(update_timestamps(operation))
    end

    def update_timestamps(operation)
      time_now = Time.current

      {
        'created_at' => (time_now if operation == :create),
        'updated_at' => time_now
      }.compact
    end
  end
end