caching 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Caching
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- Proxy.new constructor.call(*args, &block), *@cached_methods
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caching
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: