caching 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/caching/version.rb +1 -1
- data/lib/caching.rb +8 -1
- data/spec/caching_spec.rb +16 -0
- metadata +1 -1
data/lib/caching/version.rb
CHANGED
data/lib/caching.rb
CHANGED
@@ -6,7 +6,14 @@ module Caching
|
|
6
6
|
constructor = klass.method :new
|
7
7
|
|
8
8
|
klass.define_singleton_method :new do |*args, &block|
|
9
|
-
|
9
|
+
instance = constructor.call(*args, &block)
|
10
|
+
proxy = Proxy.new instance, *@cached_methods
|
11
|
+
|
12
|
+
instance.send :define_singleton_method, :clear_cache do
|
13
|
+
proxy.clear_cache
|
14
|
+
end
|
15
|
+
|
16
|
+
proxy
|
10
17
|
end
|
11
18
|
end
|
12
19
|
|
data/spec/caching_spec.rb
CHANGED
@@ -23,6 +23,10 @@ describe Caching do
|
|
23
23
|
def fast_method
|
24
24
|
@fast_method += 1
|
25
25
|
end
|
26
|
+
|
27
|
+
def reset
|
28
|
+
clear_cache
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
it 'Cache methods' do
|
@@ -58,4 +62,16 @@ describe Caching do
|
|
58
62
|
object.other_slow_method.must_equal 1
|
59
63
|
end
|
60
64
|
|
65
|
+
it 'Clear cache inside object' do
|
66
|
+
object = Cachable.new
|
67
|
+
|
68
|
+
3.times { object.slow_method.must_equal 1 }
|
69
|
+
3.times { object.other_slow_method.must_equal 1 }
|
70
|
+
|
71
|
+
object.reset
|
72
|
+
|
73
|
+
object.slow_method.must_equal 2
|
74
|
+
object.other_slow_method.must_equal 2
|
75
|
+
end
|
76
|
+
|
61
77
|
end
|