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.
20 21 22 |
# File 'lib/beaneater/stats.rb', line 20 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
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/beaneater/stats.rb', line 57 def method_missing(name, *args, &block) if caller.first !~ /`(method_missing|data')/ && data.keys.include?(name.to_s) self.class.class_eval " def \#{name}; data[\#{name.inspect}]; end\n CODE\n data[name.to_s]\n else # no key matches or caught infinite loop\n super\n end\nend\n", __FILE__, __LINE__ |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
12 13 14 |
# File 'lib/beaneater/stats.rb', line 12 def client @client end |
Instance Method Details
#[](key) ⇒ String, Integer
Returns value for specified key.
42 43 44 |
# File 'lib/beaneater/stats.rb', line 42 def [](key) data[key] end |
#data ⇒ Beaneater::StatStruct (protected)
Returns struct based on stats data from response.
77 78 79 |
# File 'lib/beaneater/stats.rb', line 77 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
49 50 51 |
# File 'lib/beaneater/stats.rb', line 49 def inspect data.to_s end |
#keys ⇒ Array<String>
Returns keys for stats data
31 32 33 |
# File 'lib/beaneater/stats.rb', line 31 def keys data.keys end |