Class: CacheKeeper::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/cache_keeper/manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManager

Returns a new instance of Manager.



4
5
6
# File 'lib/cache_keeper/manager.rb', line 4

def initialize
  self.cached_methods = []
end

Instance Attribute Details

#cached_methodsObject

Returns the value of attribute cached_methods.



2
3
4
# File 'lib/cache_keeper/manager.rb', line 2

def cached_methods
  @cached_methods
end

Instance Method Details

#activate_if_handling(klass, method_name) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/cache_keeper/manager.rb', line 24

def activate_if_handling(klass, method_name)
  cached_method = find(klass, method_name) or return

  return unless requires_activation?(cached_method)

  CacheKeeper::ReplaceMethod.replace(cached_method) do
    cached_method.call(self)
  end
end

#find(klass, method_name) ⇒ Object



8
9
10
11
12
# File 'lib/cache_keeper/manager.rb', line 8

def find(klass, method_name)
  cached_methods.find do |cached_method|
    cached_method.klass == klass && cached_method.method_name == method_name
  end
end

#handle(klass, method_name, options) ⇒ Object



18
19
20
21
22
# File 'lib/cache_keeper/manager.rb', line 18

def handle(klass, method_name, options)
  CacheKeeper::CachedMethod.new(klass, method_name, options).tap do |cached_method|
    cached_methods << cached_method
  end
end

#handled?(klass, method_name) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/cache_keeper/manager.rb', line 14

def handled?(klass, method_name)
  find(klass, method_name).present?
end