summaryrefslogtreecommitdiff
path: root/lib/gitlab/timeless.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-06-20 18:52:54 +0200
committerDouwe Maan <douwe@selenight.nl>2016-07-06 18:50:58 -0400
commit17ab745e40bf89776ab16de9ba00ebb44d1c85ca (patch)
tree007bb4a74f84d01632d9d20aa7bcec55e45078f9 /lib/gitlab/timeless.rb
parenta9fa45f09e6b6188691f37d75883b22edce7bba1 (diff)
downloadgitlab-ce-17ab745e40bf89776ab16de9ba00ebb44d1c85ca.tar.gz
Add Timeless helper module to prevent updated_at from being updated
Diffstat (limited to 'lib/gitlab/timeless.rb')
-rw-r--r--lib/gitlab/timeless.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/gitlab/timeless.rb b/lib/gitlab/timeless.rb
new file mode 100644
index 00000000000..b290c716f97
--- /dev/null
+++ b/lib/gitlab/timeless.rb
@@ -0,0 +1,16 @@
+module Gitlab
+ module Timeless
+ def self.timeless(model, &block)
+ original_record_timestamps = model.record_timestamps
+ model.record_timestamps = false
+
+ if block.arity.abs == 1
+ block.call(model)
+ else
+ block.call
+ end
+ ensure
+ model.record_timestamps = original_record_timestamps
+ end
+ end
+end