Class: SimpleFeed::Providers::Redis::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/simplefeed/providers/redis/stats.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis) ⇒ Stats

Returns a new instance of Stats.


12
13
14
# File 'lib/simplefeed/providers/redis/stats.rb', line 12

def initialize(redis)
  self.redis = redis
end

Class Attribute Details

.boot_infoObject

Returns the value of attribute boot_info


27
28
29
# File 'lib/simplefeed/providers/redis/stats.rb', line 27

def boot_info
  @boot_info
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis


10
11
12
# File 'lib/simplefeed/providers/redis/stats.rb', line 10

def redis
  @redis
end

Class Method Details

.destringify(hash) ⇒ Object

Converts strings values of a hash into floats or integers, if the string matches a corresponding pattern.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/simplefeed/providers/redis/stats.rb', line 31

def destringify(hash)
  db_hash = {}
  hash.each_pair do |key, value|
    if key =~ /^db\d+$/
      h = {}
      value.split(/,/).each do |word|
        *words      = word.split(/=/)
        h[words[0]] = words[1]
      end
      destringify(h)
      db_hash[key.gsub(/^db/, '').to_i] = h
      hash.delete(key)
    else
      hash[key] =
        if value =~ /^-?\d+$/
          value.to_i
        elsif value =~ /^-?\d*\.\d+$/
          value.to_f
        else
          value
        end
    end
  end
  hash[:dbstats] = db_hash unless db_hash.empty?
  Hashie::Mash.new(hash)
end

.load_boot_stats!Object


58
59
60
# File 'lib/simplefeed/providers/redis/stats.rb', line 58

def load_boot_stats!
  @boot_info ||= destringify(YAML.load(File.open(File.expand_path('../boot_info.yml', __FILE__))))
end

Instance Method Details

#boot_infoObject


20
21
22
# File 'lib/simplefeed/providers/redis/stats.rb', line 20

def boot_info
  self.class.boot_info
end

#infoObject


16
17
18
# File 'lib/simplefeed/providers/redis/stats.rb', line 16

def info
  self.class.destringify(redis.info)
end