Class: Amnesia::Host
- Inherits:
-
Object
show all
- Defined in:
- lib/amnesia/host.rb
Constant Summary
collapse
- FLOAT_STATS =
%w[ rusage_user rusage_system ]
- STRING_STATS =
%w[ version libevent ]
Instance Method Summary
collapse
Constructor Details
#initialize(address) ⇒ Host
Returns a new instance of Host.
8
9
10
|
# File 'lib/amnesia/host.rb', line 8
def initialize(address)
@address = address
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/amnesia/host.rb', line 18
def method_missing(method, *args)
if stats.has_key? method.to_s
value = stats[method.to_s]
if FLOAT_STATS.include? method
Float(value)
elsif STRING_STATS.include? method
value
else
Integer(value)
end
else
super
end
end
|
Instance Method Details
#address ⇒ Object
38
39
40
|
# File 'lib/amnesia/host.rb', line 38
def address
@address || @connection.servers.join(', ')
end
|
#alive? ⇒ Boolean
12
13
14
15
16
|
# File 'lib/amnesia/host.rb', line 12
def alive?
return true if connection.stats[@address]
rescue Dalli::DalliError
return false
end
|
#stats ⇒ Object
33
34
35
36
|
# File 'lib/amnesia/host.rb', line 33
def stats
stats_val = connection.stats
stats_val.values.first || {}
end
|