memoist 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/lib/memoist.rb +8 -8
- data/lib/memoist/version.rb +1 -1
- data/test/memoist_test.rb +7 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05bd6cfd3935ea3d449651b5a997497699b5ba47
|
4
|
+
data.tar.gz: 5e9fcd26cd38218270949a2757a9b1832ea63969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4369588f404fd7fa811c6b32af02998b656e13a95058018698ee9b2c67674b8da300c5ff6b736ce0d5f0a0ecbf5aee2f022756c26fce72edfea5fcad34123cd4
|
7
|
+
data.tar.gz: 9a07124cccbd25d30fbac70a2303b4b239a3871f50a261ba1d50e1a5c58402d04300fc1e930f780ceb1263f0e8097048846ea73ad4866f3c6112103ca84a596e
|
data/.travis.yml
CHANGED
data/lib/memoist.rb
CHANGED
@@ -78,7 +78,7 @@ module Memoist
|
|
78
78
|
|
79
79
|
method_names.each do |method_name|
|
80
80
|
ivar = Memoist.memoized_ivar_for(method_name)
|
81
|
-
|
81
|
+
remove_instance_variable(ivar) if instance_variable_defined?(ivar)
|
82
82
|
end
|
83
83
|
end
|
84
84
|
end
|
@@ -105,17 +105,17 @@ module Memoist
|
|
105
105
|
# define a method like this;
|
106
106
|
|
107
107
|
# def mime_type(reload=true)
|
108
|
-
# skip_cache = reload || !
|
108
|
+
# skip_cache = reload || !instance_variable_defined?("@_memoized_mime_type")
|
109
109
|
# set_cache = skip_cache && !frozen?
|
110
110
|
#
|
111
111
|
# if skip_cache
|
112
112
|
# value = _unmemoized_mime_type
|
113
113
|
# else
|
114
|
-
# value = @_memoized_mime_type
|
114
|
+
# value = @_memoized_mime_type
|
115
115
|
# end
|
116
116
|
#
|
117
117
|
# if set_cache
|
118
|
-
# @_memoized_mime_type =
|
118
|
+
# @_memoized_mime_type = value
|
119
119
|
# end
|
120
120
|
#
|
121
121
|
# value
|
@@ -123,17 +123,17 @@ module Memoist
|
|
123
123
|
|
124
124
|
module_eval <<-EOS, __FILE__, __LINE__ + 1
|
125
125
|
def #{method_name}(reload = false)
|
126
|
-
skip_cache = reload || !
|
126
|
+
skip_cache = reload || !instance_variable_defined?("#{memoized_ivar}")
|
127
127
|
set_cache = skip_cache && !frozen?
|
128
128
|
|
129
129
|
if skip_cache
|
130
130
|
value = #{unmemoized_method}
|
131
131
|
else
|
132
|
-
value = #{memoized_ivar}
|
132
|
+
value = #{memoized_ivar}
|
133
133
|
end
|
134
134
|
|
135
135
|
if set_cache
|
136
|
-
#{memoized_ivar} =
|
136
|
+
#{memoized_ivar} = value
|
137
137
|
end
|
138
138
|
|
139
139
|
value
|
@@ -167,7 +167,7 @@ module Memoist
|
|
167
167
|
def #{method_name}(*args)
|
168
168
|
reload = Memoist.extract_reload!(method(#{unmemoized_method.inspect}), args)
|
169
169
|
|
170
|
-
skip_cache = reload || !(
|
170
|
+
skip_cache = reload || !(instance_variable_defined?(#{memoized_ivar.inspect}) && #{memoized_ivar} && #{memoized_ivar}.has_key?(args))
|
171
171
|
set_cache = skip_cache && !frozen?
|
172
172
|
|
173
173
|
if skip_cache
|
data/lib/memoist/version.rb
CHANGED
data/test/memoist_test.rb
CHANGED
@@ -202,9 +202,10 @@ class MemoistTest < Test::Unit::TestCase
|
|
202
202
|
def test_flush_cache
|
203
203
|
assert_equal 1, @calculator.counter
|
204
204
|
|
205
|
-
assert @calculator.instance_variable_get(:@_memoized_counter)
|
205
|
+
assert @calculator.instance_variable_get(:@_memoized_counter)
|
206
206
|
@calculator.flush_cache(:counter)
|
207
|
-
|
207
|
+
assert_nil @calculator.instance_variable_get(:@_memoized_counter)
|
208
|
+
assert !@calculator.instance_variable_defined?(:@_memoized_counter)
|
208
209
|
|
209
210
|
assert_equal 2, @calculator.counter
|
210
211
|
end
|
@@ -212,9 +213,10 @@ class MemoistTest < Test::Unit::TestCase
|
|
212
213
|
def test_unmemoize_all
|
213
214
|
assert_equal 1, @calculator.counter
|
214
215
|
|
215
|
-
assert @calculator.instance_variable_get(:@_memoized_counter)
|
216
|
+
assert @calculator.instance_variable_get(:@_memoized_counter)
|
216
217
|
@calculator.unmemoize_all
|
217
|
-
|
218
|
+
assert_nil @calculator.instance_variable_get(:@_memoized_counter)
|
219
|
+
assert !@calculator.instance_variable_defined?(:@_memoized_counter)
|
218
220
|
|
219
221
|
assert_equal 2, @calculator.counter
|
220
222
|
end
|
@@ -329,4 +331,4 @@ class MemoistTest < Test::Unit::TestCase
|
|
329
331
|
assert_equal 1, person.is_developer_calls
|
330
332
|
end
|
331
333
|
|
332
|
-
end
|
334
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memoist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
@@ -19,7 +19,7 @@ authors:
|
|
19
19
|
autorequire:
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
|
-
date: 2014-
|
22
|
+
date: 2014-06-01 00:00:00.000000000 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: bundler
|