class ActiveSwitch::Status
Constants
- ACTIVE
- INACTIVE
Attributes
last_reported_at[R]
name[R]
threshold_seconds[R]
Public Class Methods
new(name:, last_reported_at:, threshold_seconds:)
click to toggle source
# File lib/active_switch/status.rb, line 8 def initialize(name:, last_reported_at:, threshold_seconds:) @name = name.to_s @last_reported_at = cast_timestamp(last_reported_at, cast_null: false) @threshold_seconds = threshold_seconds.to_i end
Public Instance Methods
active?()
click to toggle source
# File lib/active_switch/status.rb, line 14 def active? (cast_timestamp(last_reported_at) + threshold_seconds) > cast_timestamp(now) end
inactive?()
click to toggle source
# File lib/active_switch/status.rb, line 18 def inactive? !active? end
state()
click to toggle source
# File lib/active_switch/status.rb, line 22 def state active? ? ACTIVE : INACTIVE end
Also aliased as: to_s
Private Instance Methods
cast_timestamp(ts, cast_null: true)
click to toggle source
# File lib/active_switch/status.rb, line 33 def cast_timestamp(ts, cast_null: true) if cast_null Time.at((ts || 0).to_i) else ts ? Time.at(ts.to_i) : nil end end
now()
click to toggle source
# File lib/active_switch/status.rb, line 29 def now Time.now end