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
348 349 350 351 352 |
# File 'lib/sfn/cache.rb', line 348 def initialize(name, base, cache) @name = name.to_sym @base = base @cache = cache end |
Instance Method Details
#restamp! ⇒ Object
Force a timestamp update
379 380 381 |
# File 'lib/sfn/cache.rb', line 379 def restamp! self.value = value end |
#set? ⇒ TrueClass, FalseClass
Returns is value set.
369 370 371 |
# File 'lib/sfn/cache.rb', line 369 def set? @base.value.is_a?(Hash) end |
#stamp ⇒ Float
Returns timestamp of last set (or 0.0 if unset).
374 375 376 |
# File 'lib/sfn/cache.rb', line 374 def stamp set? ? @base.value[:stamp] : 0.0 end |
#update_allowed? ⇒ TrueClass, FalseClass
Returns update is allowed based on stamp and limits.
384 385 386 |
# File 'lib/sfn/cache.rb', line 384 def update_allowed? !set? || @cache.time_check_allow?(@name, @base.value[:stamp]) end |
#value ⇒ Object
Returns value stored.
355 356 357 |
# File 'lib/sfn/cache.rb', line 355 def value @base.value[:value] if set? end |
#value=(v) ⇒ Object
Store value and update timestamp
363 364 365 366 |
# File 'lib/sfn/cache.rb', line 363 def value=(v) @base.value = {:stamp => Time.now.to_f, :value => v} v end |