class Beaneater::Stats

Represents stats related to the beanstalkd pool.

Attributes

client[R]

@!attribute client

@return [Beaneater] returns the client instance

Public Class Methods

new(client) click to toggle source

Creates new stats instance.

@param [Beaneater] client The beaneater client instance. @example

Beaneater::Stats.new(@client)
# File lib/beaneater/stats.rb, line 18
def initialize(client)
  @client = client
end

Public Instance Methods

[](key) click to toggle source

Returns value for specified key.

@param [String,Symbol] key Name of key to retrieve @return [String,Integer] Value of specified key @example

@bp.stats['total_connections'] # => 4
# File lib/beaneater/stats.rb, line 40
def [](key)
  data[key]
end
inspect() click to toggle source

Delegates inspection to the real data structure

@return [String] returns a string containing a detailed stats summary

# File lib/beaneater/stats.rb, line 47
def inspect
  data.to_s
end
Also aliased as: to_s
keys() click to toggle source

Returns keys for stats data

@return [Array<String>] Set of keys for stats. @example

@bp.stats.keys # => ["version", "total_connections"]

@api public

# File lib/beaneater/stats.rb, line 29
def keys
  data.keys
end
method_missing(name, *args, &block) click to toggle source

Defines a cached method for looking up data for specified key Protects against infinite loops by checking stacktrace @api public

Calls superclass method
# 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
to_s()
Alias for: inspect

Protected Instance Methods

data() click to toggle source

Returns struct based on stats data from response.

@return [Beaneater::StatStruct] the stats @example

self.data # => { 'version' : 1.7, 'total_connections' : 23 }
self.data.total_connections # => 23
# File lib/beaneater/stats.rb, line 75
def data
  StatStruct.from_hash(client.connection.transmit('stats')[:body])
end