Class: SwitchGear::CircuitBreaker::Failure
- Inherits:
-
Object
- Object
- SwitchGear::CircuitBreaker::Failure
- Defined in:
- lib/switch_gear/circuit_breaker/failure.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(error, recorded = Time.now.utc) ⇒ Failure
constructor
A new instance of Failure.
- #timestamp ⇒ Object
- #to_json ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(error, recorded = Time.now.utc) ⇒ Failure
Returns a new instance of Failure
12 13 14 15 |
# File 'lib/switch_gear/circuit_breaker/failure.rb', line 12 def initialize(error, recorded = Time.now.utc) @error = error @recorded = recorded end |
Class Method Details
.from_json(json) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/switch_gear/circuit_breaker/failure.rb', line 5 def self.from_json(json) failure = JSON.parse(json) error = Object.const_get(failure["error"]) error = error.new(failure["message"]) new(error, Time.parse(failure["timestamp"])) end |
Instance Method Details
#timestamp ⇒ Object
17 18 19 |
# File 'lib/switch_gear/circuit_breaker/failure.rb', line 17 def recorded end |
#to_json ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/switch_gear/circuit_breaker/failure.rb', line 25 def to_json JSON.generate({ error: error.class, message: error., timestamp: .to_s }) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/switch_gear/circuit_breaker/failure.rb', line 21 def to_s "[#{error.class}] - #{error.}" end |