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