Class: ActiveSwitch::Status
- Inherits:
-
Object
- Object
- ActiveSwitch::Status
- Defined in:
- lib/active_switch/status.rb
Constant Summary collapse
- ACTIVE =
"ACTIVE".freeze
- INACTIVE =
"INACTIVE".freeze
Instance Attribute Summary collapse
-
#last_reported_at ⇒ Object
readonly
Returns the value of attribute last_reported_at.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#threshold_seconds ⇒ Object
readonly
Returns the value of attribute threshold_seconds.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #inactive? ⇒ Boolean
-
#initialize(name:, last_reported_at:, threshold_seconds:) ⇒ Status
constructor
A new instance of Status.
- #state ⇒ Object (also: #to_s)
Constructor Details
#initialize(name:, last_reported_at:, threshold_seconds:) ⇒ Status
Returns a new instance of Status.
8 9 10 11 12 |
# File 'lib/active_switch/status.rb', line 8 def initialize(name:, last_reported_at:, threshold_seconds:) @name = name.to_s @last_reported_at = (last_reported_at, cast_null: false) @threshold_seconds = threshold_seconds.to_i end |
Instance Attribute Details
#last_reported_at ⇒ Object (readonly)
Returns the value of attribute last_reported_at.
6 7 8 |
# File 'lib/active_switch/status.rb', line 6 def last_reported_at @last_reported_at end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_switch/status.rb', line 6 def name @name end |
#threshold_seconds ⇒ Object (readonly)
Returns the value of attribute threshold_seconds.
6 7 8 |
# File 'lib/active_switch/status.rb', line 6 def threshold_seconds @threshold_seconds end |
Instance Method Details
#active? ⇒ Boolean
14 15 16 |
# File 'lib/active_switch/status.rb', line 14 def active? ((last_reported_at) + threshold_seconds) > (now) end |
#inactive? ⇒ Boolean
18 19 20 |
# File 'lib/active_switch/status.rb', line 18 def inactive? !active? end |
#state ⇒ Object Also known as: to_s
22 23 24 |
# File 'lib/active_switch/status.rb', line 22 def state active? ? ACTIVE : INACTIVE end |