Module: TranslationDiff::Configuration::CacheTtlOption

Included in:
TranslationDiff::Configuration
Defined in:
lib/translation_diff/configuration/cache_ttl_option.rb

Overview

Prepended onto Configuration: nil sticks here as "never expires", unlike the generic option rule.

Constant Summary collapse

NEVER_ASSIGNED =
Object.new.freeze

Instance Method Summary collapse

Instance Method Details

#cache_ttl ⇒ Object



18
19
20
# File 'lib/translation_diff/configuration/cache_ttl_option.rb', line 18

def cache_ttl
  @cache_ttl.equal?(NEVER_ASSIGNED) ? self.class.defaults[:cache_ttl] : @cache_ttl
end

#cache_ttl=(value) ⇒ Object

A non-positive number folds into nil too -- a TTL of zero or less can never keep a row. Coerced here, then handed to super so the declared writer's cache_store invalidation still runs.



12
13
14
15
16
# File 'lib/translation_diff/configuration/cache_ttl_option.rb', line 12

def cache_ttl=(value)
  value = nil if value.is_a?(String) && value.strip.empty?
  value = coerce_ttl(value) if value.is_a?(String)
  super(value.is_a?(Numeric) && value <= 0 ? nil : value)
end

#initialize ⇒ Object



5
6
7
8
# File 'lib/translation_diff/configuration/cache_ttl_option.rb', line 5

def initialize
  @cache_ttl = NEVER_ASSIGNED
  super
end