Class: Pho::Status
- Inherits:
-
Object
- Object
- Pho::Status
- Defined in:
- lib/pho/status.rb
Overview
Captures status information relating to a store
Instance Attribute Summary collapse
-
#access_mode ⇒ Object
readonly
Current access mode uri.
-
#retry_interval ⇒ Object
readonly
Interval before status should be requested again.
-
#status_message ⇒ Object
readonly
Status message.
Class Method Summary collapse
-
.read_from_store(store) ⇒ Object
Create a Status object by reading the response from a store access status request.
Instance Method Summary collapse
-
#initialize(retry_interval, status_message, access_mode) ⇒ Status
constructor
A new instance of Status.
-
#readable? ⇒ Boolean
Is the store readable?.
-
#writeable? ⇒ Boolean
Is the store writeable?.
Constructor Details
#initialize(retry_interval, status_message, access_mode) ⇒ Status
Returns a new instance of Status.
25 26 27 28 29 |
# File 'lib/pho/status.rb', line 25 def initialize(retry_interval, , access_mode) @retry_interval = retry_interval @status_message = @access_mode = access_mode end |
Instance Attribute Details
#access_mode ⇒ Object (readonly)
Current access mode uri
This will be one of Pho::READ_ONLY, Pho::READ_WRITE, or Pho::UNAVAILABLE. Use the readable and writeable methods to test for the different modes
23 24 25 |
# File 'lib/pho/status.rb', line 23 def access_mode @access_mode end |
#retry_interval ⇒ Object (readonly)
Interval before status should be requested again.
14 15 16 |
# File 'lib/pho/status.rb', line 14 def retry_interval @retry_interval end |
#status_message ⇒ Object (readonly)
Status message
17 18 19 |
# File 'lib/pho/status.rb', line 17 def @status_message end |
Class Method Details
.read_from_store(store) ⇒ Object
Create a Status object by reading the response from a store access status request
The code parses the JSON output from the Platform API to create a Status object.
- store
-
the store whose status is to be read
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pho/status.rb', line 36 def Status.read_from_store(store) response = store.get_status() if (response.status != 200) raise "Cannot read store status" end u = store.build_uri("/config/access-status") json = JSON.parse( response.content ) retry_interval = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#retryInterval"][0]["value"] = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#statusMessage"][0]["value"] access_mode = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#accessMode"][0]["value"] state = Status.new(retry_interval.to_i, , access_mode) return state end |
Instance Method Details
#readable? ⇒ Boolean
Is the store readable?
54 55 56 |
# File 'lib/pho/status.rb', line 54 def readable? return @access_mode != Pho::UNAVAILABLE end |
#writeable? ⇒ Boolean
Is the store writeable?
59 60 61 |
# File 'lib/pho/status.rb', line 59 def writeable? return @access_mode == Pho::READ_WRITE end |