Class: JsonCache::CacheManager

Inherits:
Object
  • Object
show all
Includes:
FromHash
Defined in:
lib/json_cache/cache_manager.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &b) ⇒ Object



17
18
19
# File 'lib/json_cache/cache_manager.rb', line 17

def method_missing(sym,*args,&b)
  get_cache(sym).send(:get,*args,&b)
end

Instance Method Details

#get_cache(name) ⇒ Object



14
15
16
# File 'lib/json_cache/cache_manager.rb', line 14

def get_cache(name)
  caches[name.to_sym] || (raise "no cache #{name}")
end

#reg(name, ops = {}) {|res| ... } ⇒ Object

Yields:

  • (res)


5
6
7
8
# File 'lib/json_cache/cache_manager.rb', line 5

def reg(name,ops={})
  res = self.caches[name.to_sym] = JsonCache::MethodCache.new(ops.merge(:name => name))
  yield(res) if block_given?
end

#reg_simple(name, &b) ⇒ Object



9
10
11
12
13
# File 'lib/json_cache/cache_manager.rb', line 9

def reg_simple(name,&b)
  reg(name) do |c|
    c.call_blk = b
  end
end