Class: Textus::Domain::Policy::Lifecycle

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/domain/policy/lifecycle.rb

Overview

Unified per-entry lifecycle policy (ADR 0079): one ttl + one action. Replaces the separate Fetch (ttl/on_stale) and Retention (expire_after/archive_after) policies. The action’s destructiveness decides WHERE it runs: lazy actions (refresh/warn) on get/list reads; destructive actions (drop/archive) only on the tend sweep.

Constant Summary collapse

LAZY =
%i[refresh warn].freeze
DESTRUCTIVE =
%i[drop archive].freeze
ALLOWED =
(LAZY + DESTRUCTIVE).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl:, on_expire:, budget_ms: nil) ⇒ Lifecycle

Returns a new instance of Lifecycle.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/textus/domain/policy/lifecycle.rb', line 16

def initialize(ttl:, on_expire:, budget_ms: nil)
  action = on_expire.is_a?(Symbol) ? on_expire : on_expire.to_s.to_sym
  unless ALLOWED.include?(action)
    raise Textus::UsageError.new(
      "lifecycle on_expire must be one of #{ALLOWED.join("|")}, got #{on_expire.inspect}",
    )
  end

  @ttl       = ttl
  @on_expire = action
  @budget_ms = budget_ms
end

Instance Attribute Details

#budget_msObject (readonly)

Returns the value of attribute budget_ms.



14
15
16
# File 'lib/textus/domain/policy/lifecycle.rb', line 14

def budget_ms
  @budget_ms
end

#on_expireObject (readonly)

Returns the value of attribute on_expire.



14
15
16
# File 'lib/textus/domain/policy/lifecycle.rb', line 14

def on_expire
  @on_expire
end

Instance Method Details

#destructive?Boolean

Returns:

  • (Boolean)


30
# File 'lib/textus/domain/policy/lifecycle.rb', line 30

def destructive? = DESTRUCTIVE.include?(@on_expire)

#lazy?Boolean

Returns:

  • (Boolean)


31
# File 'lib/textus/domain/policy/lifecycle.rb', line 31

def lazy?        = LAZY.include?(@on_expire)

#ttl_secondsObject



29
# File 'lib/textus/domain/policy/lifecycle.rb', line 29

def ttl_seconds = Textus::Domain::Duration.seconds(@ttl)