Class: KJess::StatsCache

Inherits:
Object
  • Object
show all
Defined in:
lib/kjess/stats_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, expiration = 0) ⇒ StatsCache

Returns a new instance of StatsCache.



8
9
10
11
12
13
# File 'lib/kjess/stats_cache.rb', line 8

def initialize( client, expiration = 0 )
  @client         = client
  @expiration     = expiration
  @last_stat_time = Time.at( 0 )
  @stats          = nil
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/kjess/stats_cache.rb', line 6

def client
  @client
end

#expirationObject (readonly)

Returns the value of attribute expiration.



5
6
7
# File 'lib/kjess/stats_cache.rb', line 5

def expiration
  @expiration
end

#last_stat_timeObject (readonly)

Returns the value of attribute last_stat_time.



4
5
6
# File 'lib/kjess/stats_cache.rb', line 4

def last_stat_time
  @last_stat_time
end

Instance Method Details

#expiration_timeObject



15
16
17
# File 'lib/kjess/stats_cache.rb', line 15

def expiration_time
  last_stat_time + expiration
end

#expired?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/kjess/stats_cache.rb', line 19

def expired?
  Time.now > expiration_time
end

#statsObject



23
24
25
26
27
28
29
# File 'lib/kjess/stats_cache.rb', line 23

def stats
  if expired? then
    @stats = client.stats!
    @last_stat_time = Time.now
  end
  return @stats
end