Module: EacRubyUtils::SimpleCache

Included in:
Configs
Defined in:
lib/eac_ruby_utils/simple_cache.rb

Constant Summary collapse

UNCACHED_METHOD_PATTERN =
/\A(\s+)_uncached\z/

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/eac_ruby_utils/simple_cache.rb', line 7

def method_missing(method, *args, &block)
  uncached_method = "#{method}_uncached"
  if respond_to?(uncached_method, true)
    call_method_with_cache(uncached_method, args, &block)
  else
    super
  end
end

Instance Method Details

#reset_cacheObject



24
25
26
# File 'lib/eac_ruby_utils/simple_cache.rb', line 24

def reset_cache
  @cache_keys = nil
end

#respond_to_missing?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
# File 'lib/eac_ruby_utils/simple_cache.rb', line 16

def respond_to_missing?(method, include_all = false)
  if method.to_s.end_with?('_uncached')
    super
  else
    respond_to?("#{method}_uncached", true) || super
  end
end