mize 0.3.0 → 0.3.1
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/VERSION +1 -1
- data/lib/mize.rb +8 -0
- data/lib/mize/global_clear.rb +1 -5
- data/lib/mize/memoize.rb +20 -8
- data/lib/mize/version.rb +1 -1
- data/mize.gemspec +4 -4
- data/spec/mize/global_clear_spec.rb +8 -1
- data/spec/mize/memoize_method_spec.rb +20 -0
- data/spec/mize/memoize_reload_spec.rb +5 -1
- data/spec/mize/version_spec.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e4fc73a14f849a06c78dd20166fc33e3b10aee1
|
4
|
+
data.tar.gz: e1ba0c8d1b76b06fedec1f82d0ab249b192b4df5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83244d36a55fc6d5a3610dd16a9d048303311fbf67f777017cb18dea9eac9d3fe942e8ec2cad6ab1ee8882b3fb4ff52fd76b65e4c9d1c25b41aedbe538e2fbcf
|
7
|
+
data.tar.gz: f5ff84dca60446440666246d333adb8edf2da1e8197c0d33f4b6a8d71b45f8ef734e9a9ecc636890eadd33bc68a8ed692b63e88b2f6a5cf8c2112470078f77a8
|
data/.travis.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/mize.rb
CHANGED
data/lib/mize/global_clear.rb
CHANGED
@@ -1,8 +1,4 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
1
|
module Mize
|
4
|
-
MUTEX = Mutex.new
|
5
|
-
|
6
2
|
class << self
|
7
3
|
|
8
4
|
# Clear all memoization caches at once.
|
@@ -13,7 +9,7 @@ module Mize
|
|
13
9
|
private
|
14
10
|
|
15
11
|
def each_cache
|
16
|
-
MUTEX.synchronize do
|
12
|
+
Mize::MUTEX.synchronize do
|
17
13
|
for cache in ObjectSpace.each_object(Mize::CacheProtocol)
|
18
14
|
yield cache
|
19
15
|
end
|
data/lib/mize/memoize.rb
CHANGED
@@ -13,14 +13,16 @@ module Mize
|
|
13
13
|
# store_nil argument is false do not store nil results and always recompute
|
14
14
|
# otherwise don't which is the default.
|
15
15
|
def memoize(method: nil, function: nil, freeze: false, store_nil: true)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
Mize::MUTEX.synchronize do
|
17
|
+
if method && function
|
18
|
+
raise ArgumentError, 'memoize a method xor a function'
|
19
|
+
elsif method
|
20
|
+
wrap_method method, freeze: freeze, store_nil: store_nil
|
21
|
+
elsif function
|
22
|
+
wrap_method function, function: true, freeze: freeze, store_nil: store_nil
|
23
|
+
else
|
24
|
+
raise ArgumentError, 'missing keyword: method/function'
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -43,6 +45,15 @@ module Mize
|
|
43
45
|
|
44
46
|
def wrap_method(method_id, freeze: false, function: false, store_nil: true)
|
45
47
|
verbose, $VERBOSE = $VERBOSE, nil
|
48
|
+
if already_wrapped = Mize.wrapped[ [ self, method_id, function ] ]
|
49
|
+
if already_wrapped == [ freeze, store_nil ]
|
50
|
+
return method_id
|
51
|
+
else
|
52
|
+
raise ArgumentError,
|
53
|
+
"encountered mismatching memoize declaration within #{self} for freeze, store_nil:"\
|
54
|
+
" #{already_wrapped} != #{ [ freeze, store_nil ] }"
|
55
|
+
end
|
56
|
+
end
|
46
57
|
include CacheMethods
|
47
58
|
|
48
59
|
function and mc = __mize_cache__
|
@@ -70,6 +81,7 @@ module Mize
|
|
70
81
|
end
|
71
82
|
end
|
72
83
|
end
|
84
|
+
Mize.wrapped[ [ self, method_id, function ] ] = [ freeze, store_nil ]
|
73
85
|
method_id
|
74
86
|
ensure
|
75
87
|
$VERBOSE = verbose
|
data/lib/mize/version.rb
CHANGED
data/mize.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mize 0.3.
|
2
|
+
# stub: mize 0.3.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mize".freeze
|
6
|
-
s.version = "0.3.
|
6
|
+
s.version = "0.3.1"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Florian Frank".freeze]
|
11
|
-
s.date = "2017-
|
11
|
+
s.date = "2017-06-20"
|
12
12
|
s.description = "Library that provides memoziation for methods and functions for Ruby.".freeze
|
13
13
|
s.email = "flori@ping.de".freeze
|
14
14
|
s.extra_rdoc_files = ["README.md".freeze, "lib/mize.rb".freeze, "lib/mize/cache_methods.rb".freeze, "lib/mize/cache_protocol.rb".freeze, "lib/mize/configure.rb".freeze, "lib/mize/default_cache.rb".freeze, "lib/mize/global_clear.rb".freeze, "lib/mize/memoize.rb".freeze, "lib/mize/railtie.rb".freeze, "lib/mize/reload.rb".freeze, "lib/mize/version.rb".freeze]
|
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.licenses = ["MIT".freeze]
|
18
18
|
s.rdoc_options = ["--title".freeze, "Mize - Library that provides memoziation for methods and functions".freeze, "--main".freeze, "README.md".freeze]
|
19
19
|
s.required_ruby_version = Gem::Requirement.new(">= 2".freeze)
|
20
|
-
s.rubygems_version = "2.6.
|
20
|
+
s.rubygems_version = "2.6.11".freeze
|
21
21
|
s.summary = "Library that provides memoziation for methods and functions".freeze
|
22
22
|
s.test_files = ["spec/mize/global_clear_spec.rb".freeze, "spec/mize/memoize_method_spec.rb".freeze, "spec/mize/memoize_reload_spec.rb".freeze, "spec/mize/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
|
23
23
|
|
@@ -14,10 +14,17 @@ class Foo
|
|
14
14
|
@@foo ||= 0
|
15
15
|
@@foo += 1
|
16
16
|
end
|
17
|
-
memoize method: :foo
|
18
17
|
end
|
19
18
|
|
20
19
|
describe Mize, 'cache_clear' do
|
20
|
+
before do
|
21
|
+
Mize.wrapped.clear
|
22
|
+
|
23
|
+
class Foo
|
24
|
+
memoize method: :foo
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
21
28
|
let(:foo) { Foo.new }
|
22
29
|
|
23
30
|
describe '#cache_clear' do
|
@@ -148,6 +148,26 @@ describe Mize do
|
|
148
148
|
expect(fb1.__send__(:__mize_cache__)).to be_empty
|
149
149
|
expect(FooBar.foo_nil_not_stored).to eq 2
|
150
150
|
end
|
151
|
+
|
152
|
+
it 'only wraps once' do
|
153
|
+
class FooBar2
|
154
|
+
def foo
|
155
|
+
end
|
156
|
+
end
|
157
|
+
expect(FooBar2).to receive(:memoize_apply_visibility).and_call_original
|
158
|
+
class FooBar2
|
159
|
+
memoize method: :foo
|
160
|
+
end
|
161
|
+
expect(FooBar2).not_to receive(:memoize_apply_visibility)
|
162
|
+
class FooBar2
|
163
|
+
memoize method: :foo
|
164
|
+
end
|
165
|
+
expect do
|
166
|
+
class FooBar2
|
167
|
+
memoize method: :foo, store_nil: false
|
168
|
+
end
|
169
|
+
end.to raise_error(ArgumentError)
|
170
|
+
end
|
151
171
|
end
|
152
172
|
|
153
173
|
context 'memoize function' do
|
data/spec/mize/version_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gem_hadar
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
version: '0'
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.6.
|
164
|
+
rubygems_version: 2.6.11
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: Library that provides memoziation for methods and functions
|