mize 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/mize/cache_methods.rb +9 -0
- data/lib/mize/default_cache.rb +2 -0
- data/lib/mize/version.rb +1 -1
- data/mize.gemspec +2 -2
- data/spec/mize/global_clear_spec.rb +1 -0
- data/spec/mize/memoize_method_spec.rb +25 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 31a2249fb9449c4c378dfaa53ad98e1bdb5e4003
|
4
|
+
data.tar.gz: ce2086babe68462c54578504fd6d8fe4cec24d2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ea3e5de8e79a5941cf2512776170bb41054bb88db20f9a86cb920b0d534644a423479d3e9a77c681f88cb365fd50ec83171ea4d6285342347e1959e178f7b0a
|
7
|
+
data.tar.gz: 511cecd51e2655fa03fdeb5868754dd49704f5d44011cf488de8647791c90ed929743da4a466a37c6c789cf4e530eb985e5788c447f60060962cf376e0b7d656
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/mize/cache_methods.rb
CHANGED
@@ -8,6 +8,15 @@ module Mize::CacheMethods
|
|
8
8
|
self
|
9
9
|
end
|
10
10
|
|
11
|
+
# Clear all cached results for the method/function +name+.
|
12
|
+
def mize_cache_clear_name(name)
|
13
|
+
name = build_key_prefix(name)
|
14
|
+
__mize_cache__.each_name do |n|
|
15
|
+
n =~ %r{\A#{name}/} and __mize_cache__.delete(n)
|
16
|
+
end
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
11
20
|
private
|
12
21
|
|
13
22
|
# Set the cache object to +cache+.
|
data/lib/mize/default_cache.rb
CHANGED
data/lib/mize/version.rb
CHANGED
data/mize.gemspec
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mize 0.0
|
2
|
+
# stub: mize 0.1.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mize"
|
6
|
-
s.version = "0.0
|
6
|
+
s.version = "0.1.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
@@ -2,10 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
class FooBar
|
4
4
|
def self.reset
|
5
|
-
@@foo
|
6
|
-
@@
|
7
|
-
@@
|
8
|
-
|
5
|
+
@@foo = nil
|
6
|
+
@@footsie = nil
|
7
|
+
@@bar = nil
|
8
|
+
@@baz = nil
|
9
|
+
Mize.cache_clear
|
9
10
|
end
|
10
11
|
|
11
12
|
def foo(*a)
|
@@ -90,6 +91,16 @@ describe Mize do
|
|
90
91
|
expect(fb1.__send__(:__mize_cache__)).not_to be_empty
|
91
92
|
expect(fb2.__send__(:__mize_cache__)).not_to be_empty
|
92
93
|
end
|
94
|
+
|
95
|
+
it 'can clear caches for a single method' do
|
96
|
+
expect(fb1.__send__(:__mize_cache__)).to be_empty
|
97
|
+
expect(fb1.__send__(:footsie, 1, 2)).to eq 1
|
98
|
+
expect(fb1.foo(1)).to eq 1
|
99
|
+
fb1.mize_cache_clear_name :foo
|
100
|
+
expect(fb1.__send__(:__mize_cache__)).not_to be_empty
|
101
|
+
expect(fb1.__send__(:footsie, 1, 2)).to eq 1
|
102
|
+
expect(fb1.__send__(:foo, 1, 2)).to eq 2
|
103
|
+
end
|
93
104
|
end
|
94
105
|
|
95
106
|
context 'memoize function' do
|
@@ -120,5 +131,15 @@ describe Mize do
|
|
120
131
|
expect(fb2.__send__(:baz, 1, 2)).to eq 3
|
121
132
|
expect(FooBar.__send__(:__mize_cache__)).not_to be_empty
|
122
133
|
end
|
134
|
+
|
135
|
+
it 'can clear caches for a single function' do
|
136
|
+
expect(FooBar.__send__(:__mize_cache__)).to be_empty
|
137
|
+
expect(fb1.__send__(:baz, 1, 2)).to eq 1
|
138
|
+
expect(fb1.bar(1)).to eq 1
|
139
|
+
fb1.mize_cache_clear_name :bar
|
140
|
+
expect(FooBar.__send__(:__mize_cache__)).not_to be_empty
|
141
|
+
expect(fb1.__send__(:baz, 1, 2)).to eq 1
|
142
|
+
expect(fb1.__send__(:bar, 1, 2)).to eq 2
|
143
|
+
end
|
123
144
|
end
|
124
145
|
end
|