Class: Cash::Local
- Inherits:
-
Object
show all
- Defined in:
- lib/cash/local.rb
Instance Method Summary
collapse
Constructor Details
#initialize(remote_cache) ⇒ Local
Returns a new instance of Local.
5
6
7
|
# File 'lib/cash/local.rb', line 5
def initialize(remote_cache)
@remote_cache = remote_cache
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29
30
31
32
33
|
# File 'lib/cash/local.rb', line 29
def method_missing(method, *args, &block)
autoload_missing_constants do
@remote_cache.send(method, *args, &block)
end
end
|
Instance Method Details
#autoload_missing_constants ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/cash/local.rb', line 16
def autoload_missing_constants
yield if block_given?
rescue ArgumentError, *@remote_cache.exception_classes => error
lazy_load ||= Hash.new { |hash, hash_key| hash[hash_key] = true; false }
if error.to_s[/undefined class|referred/] && !lazy_load[error.to_s.split.last.constantize]
retry
else
raise error
end
end
|
#cache_locally ⇒ Object
9
10
11
12
13
14
|
# File 'lib/cash/local.rb', line 9
def cache_locally
@remote_cache = LocalBuffer.new(original_cache = @remote_cache)
yield if block_given?
ensure
@remote_cache = original_cache
end
|