Class: Dovado::Router::Services
- Inherits:
-
Object
- Object
- Dovado::Router::Services
- Includes:
- Celluloid
- Defined in:
- lib/dovado/router/services.rb
Overview
Router Services.
Instance Attribute Summary collapse
-
#home_automation ⇒ String
readonly
Get status of home automation service.
-
#sms ⇒ String
readonly
Get status of sms service.
Class Method Summary collapse
- .setup_supervision! ⇒ Object private
Instance Method Summary collapse
-
#[](key) ⇒ Object
Fetch an entry from the Services object.
-
#create_from_string(data_string = nil) ⇒ Services
Create a new Services object from a string with values from the router API.
-
#has_key?(key) ⇒ Boolean
Check if the Services object has a given key.
-
#home_automation? ⇒ Boolean
Boolean check if home automation is enabled.
-
#initialize(args = nil) ⇒ Services
constructor
Create a new Services object.
-
#keys ⇒ Array<Symbol>
Fetch the list of entries in the Services object.
-
#sms? ⇒ Boolean
Boolean check if sms service is enabled.
-
#update! ⇒ Object
Update the data in this Services object.
-
#valid? ⇒ Boolean
Checks if this Services object is still valid.
Constructor Details
#initialize(args = nil) ⇒ Services
Create a new Dovado::Router::Services object.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dovado/router/services.rb', line 27 def initialize(args=nil) @list = ThreadSafe::Cache.new @last_update = nil unless args.nil? args.each do |k,v| @list[Utilities.name_to_sym(k)] = v end touch! end end |
Instance Attribute Details
#home_automation ⇒ String (readonly)
Get status of home automation service
22 23 24 |
# File 'lib/dovado/router/services.rb', line 22 def home_automation @home_automation end |
#sms ⇒ String (readonly)
Get status of sms service
16 17 18 |
# File 'lib/dovado/router/services.rb', line 16 def sms @sms end |
Class Method Details
.setup_supervision! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
122 123 124 125 |
# File 'lib/dovado/router/services.rb', line 122 def self.setup_supervision! return supervise as: :router_services, size: 1 unless Actor[:router_services] return supervise as: :router_services, size: 1 if Actor[:router_services] and Actor[:router_services].dead? end |
Instance Method Details
#[](key) ⇒ Object
Fetch an entry from the Dovado::Router::Services object.
70 71 72 |
# File 'lib/dovado/router/services.rb', line 70 def [](key) @list[key] end |
#create_from_string(data_string = nil) ⇒ Services
Create a new Dovado::Router::Services object from a string with values from the router API.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dovado/router/services.rb', line 53 def create_from_string(data_string=nil) data_array = data_string.split("\n") data_array.each do |data_entry| entry_array = data_entry.split('=') if entry_array.length == 2 key = entry_array[0].downcase val = entry_array[1] keysym = Utilities.name_to_sym(key) @list[keysym] = val end end touch! end |
#has_key?(key) ⇒ Boolean
Check if the Dovado::Router::Services object has a given key.
85 86 87 |
# File 'lib/dovado/router/services.rb', line 85 def has_key?(key) keys.member?(key) end |
#home_automation? ⇒ Boolean
Boolean check if home automation is enabled
117 118 119 |
# File 'lib/dovado/router/services.rb', line 117 def home_automation? home_automation ? (home_automation == "enabled") : false end |
#keys ⇒ Array<Symbol>
Fetch the list of entries in the Dovado::Router::Services object.
77 78 79 |
# File 'lib/dovado/router/services.rb', line 77 def keys @list.keys end |
#sms? ⇒ Boolean
Boolean check if sms service is enabled
105 106 107 |
# File 'lib/dovado/router/services.rb', line 105 def sms? sms ? (sms == "enabled") : false end |
#update! ⇒ Object
Update the data in this Dovado::Router::Services object.
39 40 41 42 43 44 45 |
# File 'lib/dovado/router/services.rb', line 39 def update! client = Actor[:client] client.connect unless client.connected? client.authenticate unless client.authenticated? string = client.command('services') create_from_string string end |
#valid? ⇒ Boolean
Checks if this Dovado::Router::Services object is still valid.
92 93 94 95 |
# File 'lib/dovado/router/services.rb', line 92 def valid? return false if @last_update.nil? (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i) end |