perma_cache 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/perma_cache.rb CHANGED
@@ -85,9 +85,20 @@ module PermaCache
85
85
  PermaCache.cache.read(send("#{method_name}_perma_cache_key"))
86
86
  end
87
87
 
88
+ was_rebuilt_inst_var = "@#{method_name}_was_rebuilt"
89
+
88
90
  define_method "#{method_name}_with_perma_cache" do
91
+ instance_variable_set(was_rebuilt_inst_var , false)
92
+
89
93
  send("#{method_name}_get_perma_cache") ||
90
- send("#{method_name}!")
94
+ (
95
+ instance_variable_set(was_rebuilt_inst_var , true) &&
96
+ send("#{method_name}!")
97
+ )
98
+ end
99
+
100
+ define_method "#{method_name}_was_rebuilt?" do
101
+ instance_variable_get(was_rebuilt_inst_var ) == true
91
102
  end
92
103
 
93
104
  alias_method_chain method_name, :perma_cache
@@ -1,3 +1,3 @@
1
1
  module PermaCache
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -107,6 +107,7 @@ class PermaCacheTest < Test::Unit::TestCase
107
107
  PermaCache.cache = cache_obj
108
108
  obj.expects(:sleep).with(1).once
109
109
  assert_equal 1, obj.method1
110
+ assert obj.method1_was_rebuilt?
110
111
  end
111
112
 
112
113
  should "calling #method1 should read the cache, but not write it, if the cache is present" do
@@ -117,6 +118,7 @@ class PermaCacheTest < Test::Unit::TestCase
117
118
  PermaCache.cache = cache_obj
118
119
  obj.expects(:sleep).never
119
120
  assert_equal 123, obj.method1
121
+ assert !obj.method1_was_rebuilt?
120
122
  end
121
123
 
122
124
  should "calling #method1! should write the cache, but not read from it" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perma_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-29 00:00:00.000000000 Z
12
+ date: 2014-02-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails