1# frozen_string_literal: true
2
3module Gitlab
4  module Timeless
5    def self.timeless(model, &block)
6      original_record_timestamps = model.record_timestamps
7      model.record_timestamps = false
8
9      # negative arity means arguments are optional
10      if block.arity == 1 || block.arity < 0
11        block.call(model)
12      else
13        block.call
14      end
15
16    ensure
17      model.record_timestamps = original_record_timestamps
18    end
19  end
20end
21