Class: Textus::Domain::Policy::Refresh

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

Constant Summary collapse

ALLOWED_ON_STALE =
%i[warn sync timed_sync].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl:, on_stale:, sync_budget_ms:, fetch_timeout_seconds: nil) ⇒ Refresh

Returns a new instance of Refresh.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/textus/domain/policy/refresh.rb', line 9

def initialize(ttl:, on_stale:, sync_budget_ms:, fetch_timeout_seconds: nil)
  on_stale_sym = on_stale.is_a?(Symbol) ? on_stale : on_stale.to_s.to_sym
  unless ALLOWED_ON_STALE.include?(on_stale_sym)
    raise Textus::UsageError.new(
      "on_stale must be one of #{ALLOWED_ON_STALE.join(", ")} (got #{on_stale.inspect})",
    )
  end

  @ttl                   = ttl
  @on_stale              = on_stale_sym
  @sync_budget_ms        = sync_budget_ms
  @fetch_timeout_seconds = fetch_timeout_seconds
end

Instance Attribute Details

#fetch_timeout_secondsObject (readonly)

Returns the value of attribute fetch_timeout_seconds.



7
8
9
# File 'lib/textus/domain/policy/refresh.rb', line 7

def fetch_timeout_seconds
  @fetch_timeout_seconds
end

#on_staleObject (readonly)

Returns the value of attribute on_stale.



7
8
9
# File 'lib/textus/domain/policy/refresh.rb', line 7

def on_stale
  @on_stale
end

#sync_budget_msObject (readonly)

Returns the value of attribute sync_budget_ms.



7
8
9
# File 'lib/textus/domain/policy/refresh.rb', line 7

def sync_budget_ms
  @sync_budget_ms
end

#ttlObject (readonly)

Returns the value of attribute ttl.



7
8
9
# File 'lib/textus/domain/policy/refresh.rb', line 7

def ttl
  @ttl
end

Instance Method Details

#to_freshness_policyObject



27
28
29
30
31
32
33
# File 'lib/textus/domain/policy/refresh.rb', line 27

def to_freshness_policy
  Textus::Domain::Freshness::Policy.new(
    ttl_seconds: ttl_seconds,
    on_stale: @on_stale,
    sync_budget_ms: @sync_budget_ms,
  )
end

#ttl_secondsObject



23
24
25
# File 'lib/textus/domain/policy/refresh.rb', line 23

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