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.



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

def initialize(redis)
  self.redis = redis
end

Class Attribute Details

.boot_infoObject

Returns the value of attribute boot_info.



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

def boot_info
  @boot_info
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



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

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.



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
57
# File 'lib/simplefeed/providers/redis/stats.rb', line 32

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



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

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

Instance Method Details

#boot_infoObject



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

def boot_info
  self.class.boot_info
end

#infoObject



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

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