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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e9034cdc4e48b4728a4fc0e15332af968e79a79
4
- data.tar.gz: 483494fa7a728960a031bcd3dc1febea921d28f4
3
+ metadata.gz: 6e4fc73a14f849a06c78dd20166fc33e3b10aee1
4
+ data.tar.gz: e1ba0c8d1b76b06fedec1f82d0ab249b192b4df5
5
5
  SHA512:
6
- metadata.gz: 25ee593f7690ee48fe44def237a2c006797b23f0236779d65fab254656666a65c4b6ccf8c2c116c6e9a2c8c131a0e08bd0933f6b73938ee89748ccf26d25548b
7
- data.tar.gz: 25fe53fcbf4802c07beafc0cd8f1b2fdf76e72c3c9b1404fea676172fca927c90a176e1a3577914c26ae9f6e6e29a60c5bc1d900e2ecb3d84659eaede43bc8ad
6
+ metadata.gz: 83244d36a55fc6d5a3610dd16a9d048303311fbf67f777017cb18dea9eac9d3fe942e8ec2cad6ab1ee8882b3fb4ff52fd76b65e4c9d1c25b41aedbe538e2fbcf
7
+ data.tar.gz: f5ff84dca60446440666246d333adb8edf2da1e8197c0d33f4b6a8d71b45f8ef734e9a9ecc636890eadd33bc68a8ed692b63e88b2f6a5cf8c2112470078f77a8
@@ -3,7 +3,7 @@ rvm:
3
3
  - 2.1
4
4
  - 2.2
5
5
  - 2.3.3
6
- - 2.4.0
6
+ - 2.4.1
7
7
  - ruby-head
8
8
  matrix:
9
9
  allow_failures:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -1,4 +1,12 @@
1
+ require 'thread'
2
+
1
3
  module Mize
4
+ MUTEX = Mutex.new
5
+
6
+ class << self
7
+ attr_accessor :wrapped
8
+ end
9
+ self.wrapped = {}
2
10
  end
3
11
 
4
12
  require 'mize/version'
@@ -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
@@ -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
- if method && function
17
- raise ArgumentError, 'memoize a method xor a function'
18
- elsif method
19
- wrap_method method, freeze: freeze, store_nil: store_nil
20
- elsif function
21
- wrap_method function, function: true, freeze: freeze, store_nil: store_nil
22
- else
23
- raise ArgumentError, 'missing keyword: method/function'
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
@@ -1,6 +1,6 @@
1
1
  module Mize
2
2
  # Mize version
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mize 0.3.0 ruby lib
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.0"
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-02-27"
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.10".freeze
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
@@ -14,11 +14,15 @@ 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::Reload do
21
20
  before do
21
+ Mize.wrapped.clear
22
+
23
+ class Foo
24
+ memoize method: :foo
25
+ end
22
26
  Foo.reset
23
27
  end
24
28
 
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Mize::VERSION do
3
+ describe 'Mize::VERSION' do
4
4
  it 'has a version' do
5
5
  expect(Mize::VERSION).to be_a String
6
- expect(Mize::VERSION).to match /\d+./
6
+ expect(Mize::VERSION).to match(/\d+./)
7
7
  end
8
8
  end
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.0
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-02-27 00:00:00.000000000 Z
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.10
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