memoist 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +3 -1
- data/lib/memoist.rb +6 -2
- data/lib/memoist/core_ext/singleton_class.rb +1 -0
- data/lib/memoist/version.rb +2 -1
- data/memoist.gemspec +1 -0
- data/script/benchmark.rb +48 -0
- data/test/memoist_test.rb +9 -10
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c78fdf779defabcfac8c1f22986ed304dca27f
|
4
|
+
data.tar.gz: f2f2c12536a72bebf60ffc455c3c24fdb93bf6e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda92d74b0dab9e6c9ac5490cc2ad452df815260811069e9ac3d0d1fe0fee074525a665dc46f7ac51ea6a74c83fac495b1f4a4c3443b8e64e27a0bb920df65ac
|
7
|
+
data.tar.gz: c3b9ea4fcecd032e6f0b78fcc5209df4297180fb75b6324b117d57cddf76cbde8d5edbda436c53d6398c173262a6594ed6b32ab8d9897cc31003fc68bf54d8c3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
Memoist
|
2
2
|
=============
|
3
3
|
|
4
|
-
[![Build Status](https://travis-ci.org/matthewrudy/memoist.
|
4
|
+
[![Build Status](https://travis-ci.org/matthewrudy/memoist.svg?branch=master)](https://travis-ci.org/matthewrudy/memoist)
|
5
|
+
|
6
|
+
[![ghit.me](https://ghit.me/badge.svg?repo=matthewrudy/memoist)](https://ghit.me/repo/matthewrudy/memoist)
|
5
7
|
|
6
8
|
Memoist is an extraction of ActiveSupport::Memoizable.
|
7
9
|
|
data/lib/memoist.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'memoist/version'
|
1
3
|
require 'memoist/core_ext/singleton_class'
|
2
4
|
|
3
5
|
module Memoist
|
@@ -115,8 +117,10 @@ module Memoist
|
|
115
117
|
end
|
116
118
|
|
117
119
|
Memoist.memoist_eval(self) do
|
118
|
-
|
119
|
-
|
120
|
+
unless singleton_class.method_defined?(:memoized_methods)
|
121
|
+
def self.memoized_methods
|
122
|
+
@_memoized_methods ||= []
|
123
|
+
end
|
120
124
|
end
|
121
125
|
end
|
122
126
|
|
data/lib/memoist/version.rb
CHANGED
data/memoist.gemspec
CHANGED
@@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
33
33
|
spec.require_paths = ["lib"]
|
34
34
|
|
35
|
+
spec.add_development_dependency "benchmark-ips"
|
35
36
|
spec.add_development_dependency "bundler"
|
36
37
|
spec.add_development_dependency "rake"
|
37
38
|
spec.add_development_dependency "minitest", "~> 5.5.1"
|
data/script/benchmark.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__)+"/../lib")
|
2
|
+
require 'benchmark/ips'
|
3
|
+
|
4
|
+
require 'memoist'
|
5
|
+
|
6
|
+
class Benchy
|
7
|
+
extend Memoist
|
8
|
+
|
9
|
+
def arity_0
|
10
|
+
"Hello World"
|
11
|
+
end
|
12
|
+
memoize :arity_0
|
13
|
+
|
14
|
+
def arity_1(name)
|
15
|
+
"Hello #{name}"
|
16
|
+
end
|
17
|
+
memoize :arity_1
|
18
|
+
end
|
19
|
+
|
20
|
+
OBJECT = Benchy.new
|
21
|
+
|
22
|
+
puts "Benchmarking: #{Memoist::VERSION}"
|
23
|
+
|
24
|
+
Benchmark.ips do |x|
|
25
|
+
x.report("arity 0 - memoized") do |times|
|
26
|
+
times.times do
|
27
|
+
OBJECT.arity_0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# x.report("arity 0 - unmemoized") do |times|
|
32
|
+
# times.times do
|
33
|
+
# OBJECT._unmemoized_arity_0
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
|
37
|
+
x.report("arity 1 - memoized") do |times|
|
38
|
+
times.times do
|
39
|
+
OBJECT.arity_1(:World)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# x.report("arity 1 - unmemoized") do |times|
|
44
|
+
# times.times do
|
45
|
+
# OBJECT._unmemoized_arity_1(:World)
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
end
|
data/test/memoist_test.rb
CHANGED
@@ -251,8 +251,7 @@ class MemoistTest < Minitest::Test
|
|
251
251
|
|
252
252
|
assert @calculator.instance_variable_get(:@_memoized_counter)
|
253
253
|
@calculator.flush_cache(:counter)
|
254
|
-
|
255
|
-
assert !@calculator.instance_variable_defined?(:@_memoized_counter)
|
254
|
+
assert_equal false, @calculator.instance_variable_defined?(:@_memoized_counter)
|
256
255
|
|
257
256
|
assert_equal 2, @calculator.counter
|
258
257
|
end
|
@@ -260,10 +259,10 @@ class MemoistTest < Minitest::Test
|
|
260
259
|
def test_unmemoize_all
|
261
260
|
assert_equal 1, @calculator.counter
|
262
261
|
|
262
|
+
assert_equal true, @calculator.instance_variable_defined?(:@_memoized_counter)
|
263
263
|
assert @calculator.instance_variable_get(:@_memoized_counter)
|
264
264
|
@calculator.unmemoize_all
|
265
|
-
|
266
|
-
assert !@calculator.instance_variable_defined?(:@_memoized_counter)
|
265
|
+
assert_equal false, @calculator.instance_variable_defined?(:@_memoized_counter)
|
267
266
|
|
268
267
|
assert_equal 2, @calculator.counter
|
269
268
|
end
|
@@ -301,21 +300,21 @@ class MemoistTest < Minitest::Test
|
|
301
300
|
assert_equal "very_senior", teacher.instance_variable_get(:@_memoized_seniority)
|
302
301
|
|
303
302
|
teacher.unmemoize_all
|
304
|
-
|
305
|
-
|
303
|
+
assert_equal false, teacher.instance_variable_defined?(:@_memoized_name)
|
304
|
+
assert_equal false, teacher.instance_variable_defined?(:@_memoized_seniority)
|
306
305
|
|
307
306
|
student = Student.new
|
308
307
|
assert_equal "Student Josh", student.name
|
309
308
|
assert_equal "Student Josh", student.instance_variable_get(:@_memoized_student_name)
|
310
|
-
|
309
|
+
assert_equal false, student.instance_variable_defined?(:@_memoized_seniority)
|
311
310
|
|
312
311
|
student.unmemoize_all
|
313
|
-
|
312
|
+
assert_equal false, @calculator.instance_variable_defined?(:@_memoized_student_name)
|
314
313
|
end
|
315
314
|
|
316
315
|
def test_memoize_all
|
317
316
|
@calculator.memoize_all
|
318
|
-
|
317
|
+
assert_equal true, @calculator.instance_variable_defined?(:@_memoized_counter)
|
319
318
|
end
|
320
319
|
|
321
320
|
def test_memoize_all_subclasses
|
@@ -334,7 +333,7 @@ class MemoistTest < Minitest::Test
|
|
334
333
|
|
335
334
|
assert_equal "Student Josh", student.instance_variable_get(:@_memoized_student_name)
|
336
335
|
assert_equal "Student Josh", student.name
|
337
|
-
|
336
|
+
assert_equal false, student.instance_variable_defined?(:@_memoized_seniority)
|
338
337
|
end
|
339
338
|
|
340
339
|
def test_memoization_cache_is_different_for_each_instance
|
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.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
@@ -19,8 +19,22 @@ authors:
|
|
19
19
|
autorequire:
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
|
-
date:
|
22
|
+
date: 2016-08-23 00:00:00.000000000 Z
|
23
23
|
dependencies:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: benchmark-ips
|
26
|
+
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
type: :development
|
32
|
+
prerelease: false
|
33
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
24
38
|
- !ruby/object:Gem::Dependency
|
25
39
|
name: bundler
|
26
40
|
requirement: !ruby/object:Gem::Requirement
|
@@ -91,6 +105,7 @@ files:
|
|
91
105
|
- lib/memoist/core_ext/singleton_class.rb
|
92
106
|
- lib/memoist/version.rb
|
93
107
|
- memoist.gemspec
|
108
|
+
- script/benchmark.rb
|
94
109
|
- test/memoist_test.rb
|
95
110
|
- test/test_helper.rb
|
96
111
|
homepage: https://github.com/matthewrudy/memoist
|
@@ -113,11 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
128
|
version: '0'
|
114
129
|
requirements: []
|
115
130
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.5.1
|
117
132
|
signing_key:
|
118
133
|
specification_version: 4
|
119
134
|
summary: memoize methods invocation
|
120
135
|
test_files:
|
121
136
|
- test/memoist_test.rb
|
122
137
|
- test/test_helper.rb
|
123
|
-
has_rdoc:
|