Sha256: 2a645892a3876f6dab4ae252f1ea34cc74e843fc09195ed21a1406c029106ebb
Contents?: true
Size: 1.46 KB
Versions: 5
Compression:
Stored size: 1.46 KB
Contents
require "infopark_component_cache/guards/cms_state_guard" module InfoparkComponentCache module Guards # @author Tomasz Przedmojski <tomasz.przedmojski@infopark.de> # # This guard ensures that any object that becomes valid (through valid_from) # will cause inconsistency class ValidFrom < CmsStateGuard def consistent? if min_valid_from_known? return no_changes_since? else return current_min_valid_from.nil? end end def guard! cache.write(cache_key, current_min_valid_from) end # @return true if a timestamp can be read from cache with {#cache_key} def min_valid_from_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Time) end # @return true if no obj has been changed since last {#guard!} def no_changes_since? current_min_valid_from == cache.read(cache_key) && current_min_valid_from > Time.now end # @return [String] the cache key for storing {#current_min_valid_from} def cache_key component.cache_key('min_valid_from') end # @return [Time] the timestamp of the most recent valid_from, or nil if none found def current_min_valid_from str_value = scoped_relation.where('valid_from > ?', Time.now.to_iso).minimum(:valid_from) if str_value.present? RailsConnector::DateAttribute.parse(str_value) else nil end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems