Class: KJess::StatsCache
- Inherits:
-
Object
- Object
- KJess::StatsCache
- Defined in:
- lib/kjess/stats_cache.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#expiration ⇒ Object
readonly
Returns the value of attribute expiration.
-
#last_stat_time ⇒ Object
readonly
Returns the value of attribute last_stat_time.
Instance Method Summary collapse
- #expiration_time ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(client, expiration = 0) ⇒ StatsCache
constructor
A new instance of StatsCache.
- #stats ⇒ Object
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
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/kjess/stats_cache.rb', line 6 def client @client end |
#expiration ⇒ Object (readonly)
Returns the value of attribute expiration.
5 6 7 |
# File 'lib/kjess/stats_cache.rb', line 5 def expiration @expiration end |
#last_stat_time ⇒ Object (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_time ⇒ Object
15 16 17 |
# File 'lib/kjess/stats_cache.rb', line 15 def expiration_time last_stat_time + expiration end |
#expired? ⇒ Boolean
19 20 21 |
# File 'lib/kjess/stats_cache.rb', line 19 def expired? Time.now > expiration_time end |
#stats ⇒ Object
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 |