2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-20 12:52:54 -04:00
|
|
|
module Gitlab
|
|
|
|
module Timeless
|
|
|
|
def self.timeless(model, &block)
|
|
|
|
original_record_timestamps = model.record_timestamps
|
|
|
|
model.record_timestamps = false
|
|
|
|
|
2021-08-20 17:10:36 -04:00
|
|
|
# negative arity means arguments are optional
|
|
|
|
if block.arity == 1 || block.arity < 0
|
2016-06-20 12:52:54 -04:00
|
|
|
block.call(model)
|
|
|
|
else
|
|
|
|
block.call
|
|
|
|
end
|
2018-01-11 11:34:01 -05:00
|
|
|
|
2016-06-20 12:52:54 -04:00
|
|
|
ensure
|
|
|
|
model.record_timestamps = original_record_timestamps
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|