Class: InfoparkComponentCache::Guards::ValidFrom
- Inherits:
-
CmsStateGuard
- Object
- ConsistencyGuard
- CmsStateGuard
- InfoparkComponentCache::Guards::ValidFrom
- Defined in:
- lib/infopark_component_cache/guards/valid_from.rb
Overview
This guard ensures that any object that becomes valid (through valid_from) will cause inconsistency
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ConsistencyGuard
Instance Method Summary collapse
-
#cache_key ⇒ String
The cache key for storing #current_min_valid_from.
- #consistent? ⇒ Boolean
-
#current_min_valid_from ⇒ Time
The timestamp of the most recent valid_from, or nil if none found.
- #guard! ⇒ Object
-
#min_valid_from_known? ⇒ Boolean
True if a timestamp can be read from cache with #cache_key.
-
#no_changes_since? ⇒ Boolean
True if no obj has been changed since last #guard!.
Methods inherited from ConsistencyGuard
Constructor Details
This class inherits a constructor from InfoparkComponentCache::ConsistencyGuard
Instance Method Details
#cache_key ⇒ String
Returns the cache key for storing #current_min_valid_from.
33 34 35 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 33 def cache_key component.cache_key('min_valid_from') end |
#consistent? ⇒ Boolean
10 11 12 13 14 15 16 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 10 def consistent? if min_valid_from_known? return no_changes_since? else return current_min_valid_from.nil? end end |
#current_min_valid_from ⇒ Time
Returns the timestamp of the most recent valid_from, or nil if none found.
38 39 40 41 42 43 44 45 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 38 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 |
#guard! ⇒ Object
18 19 20 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 18 def guard! cache.write(cache_key, current_min_valid_from) end |
#min_valid_from_known? ⇒ Boolean
Returns true if a timestamp can be read from cache with #cache_key.
23 24 25 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 23 def min_valid_from_known? cache.exist?(cache_key) && cache.read(cache_key).kind_of?(Time) end |
#no_changes_since? ⇒ Boolean
Returns true if no obj has been changed since last #guard!.
28 29 30 |
# File 'lib/infopark_component_cache/guards/valid_from.rb', line 28 def no_changes_since? current_min_valid_from == cache.read(cache_key) && current_min_valid_from > Time.now end |