Class: TempoIQ::WriteResponse
- Inherits:
-
Object
- Object
- TempoIQ::WriteResponse
- Defined in:
- lib/tempoiq/models/write_response.rb
Overview
WriteResponse is used to track the status of a write. Because writes are bulk in nature (writing to multiple devices and sensors at once), there are instances where some writes device writes may succeed and some might fail in the same write call.
- High level introspection
-
#success?
-
#partial_success?
-
- Device level introspection
-
#failures
-
#created
-
#existing
-
#modified
-
Instance Attribute Summary collapse
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#created ⇒ Object
Devices that were created during the write.
-
#existing ⇒ Object
Devices that already existed before the write.
-
#failures ⇒ Object
Retrieve the failures, key => message [Hash].
-
#initialize(status = nil) ⇒ WriteResponse
constructor
A new instance of WriteResponse.
-
#modified ⇒ Object
Devices that were modified (eg - sensors added) during the write.
-
#partial_success? ⇒ Boolean
Did the write have partial failures?.
-
#success? ⇒ Boolean
Was the write a total success?.
Constructor Details
#initialize(status = nil) ⇒ WriteResponse
Returns a new instance of WriteResponse.
19 20 21 |
# File 'lib/tempoiq/models/write_response.rb', line 19 def initialize(status = nil) @status = status end |
Instance Attribute Details
#status ⇒ Object (readonly)
Returns the value of attribute status.
17 18 19 |
# File 'lib/tempoiq/models/write_response.rb', line 17 def status @status end |
Instance Method Details
#created ⇒ Object
Devices that were created during the write
49 50 51 |
# File 'lib/tempoiq/models/write_response.rb', line 49 def created status.select { |device_key, v| v["device_state"] == "created" } end |
#existing ⇒ Object
Devices that already existed before the write
44 45 46 |
# File 'lib/tempoiq/models/write_response.rb', line 44 def existing status.select { |device_key, v| v["device_state"] == "existing" } end |
#failures ⇒ Object
Retrieve the failures, key => message [Hash]
39 40 41 |
# File 'lib/tempoiq/models/write_response.rb', line 39 def failures status.select { |device_key, v| v["successful"] == false } end |
#modified ⇒ Object
Devices that were modified (eg - sensors added) during the write
54 55 56 |
# File 'lib/tempoiq/models/write_response.rb', line 54 def modified status.select { |device_key, v| v["device_state"] == "modified" } end |
#partial_success? ⇒ Boolean
Did the write have partial failures?
34 35 36 |
# File 'lib/tempoiq/models/write_response.rb', line 34 def partial_success? !success? end |
#success? ⇒ Boolean
Was the write a total success?
24 25 26 27 28 29 30 31 |
# File 'lib/tempoiq/models/write_response.rb', line 24 def success? status.each do |key,device_status| if device_status['successful'] == false return false end end true end |