2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
module Gitlab
|
|
|
|
module Timeless
|
|
|
|
def self.timeless(model, &block)
|
|
|
|
original_record_timestamps = model.record_timestamps
|
|
|
|
model.record_timestamps = false
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
# negative arity means arguments are optional
|
|
|
|
if block.arity == 1 || block.arity < 0
|
2023-03-04 22:38:38 +05:30
|
|
|
yield(model)
|
2016-08-24 12:49:21 +05:30
|
|
|
else
|
2023-03-04 22:38:38 +05:30
|
|
|
yield
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
ensure
|
|
|
|
model.record_timestamps = original_record_timestamps
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|