diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-05-08 12:20:54 +0200 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-05-08 12:20:54 +0200 |
commit | 7be65f5d8fd7789b6f630ea04b7bcec8847ab436 (patch) | |
tree | aa6ca735446ed4fc6ce8a9b0d3ec1b01082da5e9 | |
parent | c8bfb3e418b0dcce8b3f3bec91bb2ae64f0fe19d (diff) | |
download | gitlab-ce-7be65f5d8fd7789b6f630ea04b7bcec8847ab436.tar.gz |
Add cached_attr_time_reader to RedisCacheable
-rw-r--r-- | app/models/concerns/redis_cacheable.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/concerns/redis_cacheable.rb b/app/models/concerns/redis_cacheable.rb index b889f4202dc..0dd15734eae 100644 --- a/app/models/concerns/redis_cacheable.rb +++ b/app/models/concerns/redis_cacheable.rb @@ -12,6 +12,15 @@ module RedisCacheable end end end + + def cached_attr_time_reader(*attributes) + attributes.each do |attribute| + define_method("#{attribute}") do + cached_value = cached_attribute(attribute) + cached_value ? Time.zone.parse(cached_value) : read_attribute(attribute) + end + end + end end def cached_attribute(attribute) |