Module: EacRubyUtils::SimpleCache
Constant Summary
collapse
- UNCACHED_METHOD_PATTERN =
/\A(\s+)_uncached\z/.freeze
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_cache(*keys) ⇒ Object
24
25
26
27
28
29
30
|
# File 'lib/eac_ruby_utils/simple_cache.rb', line 24
def reset_cache(*keys)
if keys.any?
keys.each { |key| cache_keys.delete(key) }
else
@cache_keys = nil
end
end
|
#respond_to_missing?(method, include_all = false) ⇒ 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
|