Class: Textus::Domain::Freshness

Inherits:
Data
  • Object
show all
Defined in:
lib/textus/domain/freshness.rb,
lib/textus/domain/freshness/policy.rb,
lib/textus/domain/freshness/verdict.rb,
lib/textus/domain/freshness/evaluator.rb

Overview

Value object describing the freshness annotation attached to an Envelope after a freshness evaluation. Replaces the loose Hash that used to live on ‘Envelope#freshness`.

Note on wire format: ‘#to_h_for_wire` is intentionally narrower than the full field set. It emits the legacy keys (“stale”, “stale_reason”, “refreshing”, and “refresh_error” when present) so the CLI JSON wire stays byte-identical with textus/3. The gem-side fields `checked_at` and `ttl_remaining_ms` are NOT emitted on the wire in this phase.

Defined Under Namespace

Modules: Evaluator Classes: Policy, Verdict

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#checked_atObject (readonly)

Returns the value of attribute checked_at

Returns:

  • (Object)

    the current value of checked_at



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

def checked_at
  @checked_at
end

#reasonObject (readonly)

Returns the value of attribute reason

Returns:

  • (Object)

    the current value of reason



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

def reason
  @reason
end

#refresh_errorObject (readonly)

Returns the value of attribute refresh_error

Returns:

  • (Object)

    the current value of refresh_error



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

def refresh_error
  @refresh_error
end

#refreshingObject (readonly)

Returns the value of attribute refreshing

Returns:

  • (Object)

    the current value of refreshing



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

def refreshing
  @refreshing
end

#staleObject (readonly)

Returns the value of attribute stale

Returns:

  • (Object)

    the current value of stale



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

def stale
  @stale
end

#ttl_remaining_msObject (readonly)

Returns the value of attribute ttl_remaining_ms

Returns:

  • (Object)

    the current value of ttl_remaining_ms



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

def ttl_remaining_ms
  @ttl_remaining_ms
end

Class Method Details

.build(stale:, refreshing: false, reason: nil, refresh_error: nil, checked_at: nil, ttl_remaining_ms: nil) ⇒ Object



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

def self.build(stale:, refreshing: false, reason: nil, refresh_error: nil,
               checked_at: nil, ttl_remaining_ms: nil)
  new(
    stale: stale,
    refreshing: refreshing,
    reason: reason,
    refresh_error: refresh_error,
    checked_at: checked_at,
    ttl_remaining_ms: ttl_remaining_ms,
  )
end

Instance Method Details

#to_h_for_wireObject



29
30
31
32
33
34
35
36
37
# File 'lib/textus/domain/freshness.rb', line 29

def to_h_for_wire
  h = {
    "stale" => stale,
    "stale_reason" => reason,
    "refreshing" => refreshing,
  }
  h["refresh_error"] = refresh_error unless refresh_error.nil?
  h
end