summaryrefslogtreecommitdiff
path: root/app/services/concerns/audit_event_save_type.rb
blob: 6696e4adae7677c553514e5eef8d77c02c556afe (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
# frozen_string_literal: true

module AuditEventSaveType
  SAVE_TYPES = {
    database: 0b01,
    stream: 0b10,
    database_and_stream: 0b11
  }.freeze

  # def should_save_stream?(type)
  # def should_save_database?(type)
  [:database, :stream].each do |type|
    define_method("should_save_#{type}?") do |param_type|
      return false unless save_type_valid?(param_type)

      # If the current type does not support query, the result of the `&` operation is 0 .
      SAVE_TYPES[param_type] & SAVE_TYPES[type] != 0
    end
  end

  private

  def save_type_valid?(type)
    SAVE_TYPES.key?(type)
  end
end