Module: InfoparkComponentCache::DelayedGuard::ClassMethods

Defined in:
lib/infopark_component_cache/delayed_guard.rb

Instance Method Summary collapse

Instance Method Details

#delay(method_name, options) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/infopark_component_cache/delayed_guard.rb', line 48

def delay(method_name, options)
  expiration = options[:for]
  return unless expiration

  # allow to overwrite the delays
  alias_method :"delayed_#{method_name}", method_name unless method_defined?(:"delayed_#{method_name}")
  define_method method_name do
    value = delayed_value(method_name)
    if still_delayed?(method_name)
      value
    else
      delay_value(method_name, send(:"delayed_#{method_name}"), expiration)
    end
  end
end