summaryrefslogtreecommitdiff
path: root/lib/gitlab/timeless.rb
blob: ed0b7b4ed872af1fe1ac4586d03f09d1f707b66b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# frozen_string_literal: true

module Gitlab
  module Timeless
    def self.timeless(model, &block)
      original_record_timestamps = model.record_timestamps
      model.record_timestamps = false

      # negative arity means arguments are optional
      if block.arity == 1 || block.arity < 0
        yield(model)
      else
        yield
      end

    ensure
      model.record_timestamps = original_record_timestamps
    end
  end
end