Class: Beaneater::Stats
- Inherits:
-
Object
- Object
- Beaneater::Stats
- Defined in:
- lib/beaneater/stats.rb
Overview
Represents stats related to the beanstalkd pool.
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#[](key) ⇒ String, Integer
Returns value for specified key.
-
#data ⇒ Beaneater::StatStruct
protected
Returns struct based on stats data from response.
-
#initialize(client) ⇒ Stats
constructor
Creates new stats instance.
-
#inspect ⇒ String
(also: #to_s)
Delegates inspection to the real data structure.
-
#keys ⇒ Array<String>
Returns keys for stats data.
-
#method_missing(name, *args, &block) ⇒ Object
Defines a cached method for looking up data for specified key Protects against infinite loops by checking stacktrace.
Constructor Details
#initialize(client) ⇒ Stats
Creates new stats instance.
18 19 20 |
# File 'lib/beaneater/stats.rb', line 18 def initialize(client) @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Defines a cached method for looking up data for specified key Protects against infinite loops by checking stacktrace
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/beaneater/stats.rb', line 55 def method_missing(name, *args, &block) if caller.first !~ /`(method_missing|data')/ && data.keys.include?(name.to_s) self.class.class_eval <<-CODE, __FILE__, __LINE__ def #{name}; data[#{name.inspect}]; end CODE data[name.to_s] else # no key matches or caught infinite loop super end end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
10 11 12 |
# File 'lib/beaneater/stats.rb', line 10 def client @client end |
Instance Method Details
#[](key) ⇒ String, Integer
Returns value for specified key.
40 41 42 |
# File 'lib/beaneater/stats.rb', line 40 def [](key) data[key] end |
#data ⇒ Beaneater::StatStruct (protected)
Returns struct based on stats data from response.
75 76 77 |
# File 'lib/beaneater/stats.rb', line 75 def data StatStruct.from_hash(client.connection.transmit('stats')[:body]) end |
#inspect ⇒ String Also known as: to_s
Delegates inspection to the real data structure
47 48 49 |
# File 'lib/beaneater/stats.rb', line 47 def inspect data.to_s end |
#keys ⇒ Array<String>
Returns keys for stats data
29 30 31 |
# File 'lib/beaneater/stats.rb', line 29 def keys data.keys end |