Class: Sfn::Cache::Stamped
- Inherits:
-
Object
- Object
- Sfn::Cache::Stamped
- Defined in:
- lib/sfn/cache.rb
Overview
Wrapper to auto stamp values
Instance Method Summary collapse
-
#initialize(name, base, cache) ⇒ Stamped
constructor
Create new instance.
-
#restamp! ⇒ Object
Force a timestamp update.
-
#set? ⇒ TrueClass, FalseClass
Is value set.
-
#stamp ⇒ Float
Timestamp of last set (or 0.0 if unset).
-
#update_allowed? ⇒ TrueClass, FalseClass
Update is allowed based on stamp and limits.
-
#value ⇒ Object
Value stored.
-
#value=(v) ⇒ Object
Store value and update timestamp.
Constructor Details
#initialize(name, base, cache) ⇒ Stamped
Create new instance
350 351 352 353 354 |
# File 'lib/sfn/cache.rb', line 350 def initialize(name, base, cache) @name = name.to_sym @base = base @cache = cache end |
Instance Method Details
#restamp! ⇒ Object
Force a timestamp update
381 382 383 |
# File 'lib/sfn/cache.rb', line 381 def restamp! self.value = value end |
#set? ⇒ TrueClass, FalseClass
Returns is value set.
371 372 373 |
# File 'lib/sfn/cache.rb', line 371 def set? @base.value.is_a?(Hash) end |
#stamp ⇒ Float
Returns timestamp of last set (or 0.0 if unset).
376 377 378 |
# File 'lib/sfn/cache.rb', line 376 def stamp set? ? @base.value[:stamp] : 0.0 end |
#update_allowed? ⇒ TrueClass, FalseClass
Returns update is allowed based on stamp and limits.
386 387 388 |
# File 'lib/sfn/cache.rb', line 386 def update_allowed? !set? || @cache.time_check_allow?(@name, @base.value[:stamp]) end |
#value ⇒ Object
Returns value stored.
357 358 359 |
# File 'lib/sfn/cache.rb', line 357 def value @base.value[:value] if set? end |
#value=(v) ⇒ Object
Store value and update timestamp
365 366 367 368 |
# File 'lib/sfn/cache.rb', line 365 def value=(v) @base.value = {:stamp => Time.now.to_f, :value => v} v end |