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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aca25d96c69122d50102f2d9615409389004002e
4
- data.tar.gz: db741378eab95d22ee2b6e6b9cde18fb4ec2abdb
3
+ metadata.gz: c9c78fdf779defabcfac8c1f22986ed304dca27f
4
+ data.tar.gz: f2f2c12536a72bebf60ffc455c3c24fdb93bf6e1
5
5
  SHA512:
6
- metadata.gz: 1307707c8feba8c316cb1628503b76fde33e5c04b62de897c6350edc67333f325d652b45b614ecb4365229e909c7869e71c2713272b971826f8e33c7ddcbb566
7
- data.tar.gz: 8b8141373347a9b87b7923fca58c3d3fb1daaa660af63ca765d1f9654343a77dbd915b3a8e0b89188870222a3d85cf8c9e9dba4d2af638cda4a63c50530c2acd
6
+ metadata.gz: fda92d74b0dab9e6c9ac5490cc2ad452df815260811069e9ac3d0d1fe0fee074525a665dc46f7ac51ea6a74c83fac495b1f4a4c3443b8e64e27a0bb920df65ac
7
+ data.tar.gz: c3b9ea4fcecd032e6f0b78fcc5209df4297180fb75b6324b117d57cddf76cbde8d5edbda436c53d6398c173262a6594ed6b32ab8d9897cc31003fc68bf54d8c3
@@ -1,3 +1,5 @@
1
+ sudo: false
2
+ cache: bundler
1
3
  language: ruby
2
4
  rvm:
3
5
  - 1.8.7
@@ -6,6 +8,7 @@ rvm:
6
8
  - 2.0.0
7
9
  - 2.1.0
8
10
  - 2.2.0
11
+ - 2.3.0
9
12
  - jruby-18mode
10
13
  - jruby-19mode
11
14
  - rbx-2
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  Memoist
2
2
  =============
3
3
 
4
- [![Build Status](https://travis-ci.org/matthewrudy/memoist.png?branch=master)](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
 
@@ -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
- def self.memoized_methods
119
- @_memoized_methods ||= []
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
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Kernel
2
3
  # Returns the object's singleton class.
3
4
  def singleton_class
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Memoist
2
- VERSION = "0.14.0"
3
+ VERSION = "0.15.0"
3
4
  end
@@ -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"
@@ -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
@@ -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
- assert_nil @calculator.instance_variable_get(:@_memoized_counter)
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
- assert_nil @calculator.instance_variable_get(:@_memoized_counter)
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
- assert_nil teacher.instance_variable_get(:@_memoized_name)
305
- assert_nil teacher.instance_variable_get(:@_memoized_seniority)
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
- assert_nil student.instance_variable_get(:@_memoized_seniority)
309
+ assert_equal false, student.instance_variable_defined?(:@_memoized_seniority)
311
310
 
312
311
  student.unmemoize_all
313
- assert_nil student.instance_variable_get(:@_memoized_student_name)
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
- assert @calculator.instance_variable_defined?(:@_memoized_counter)
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
- assert_nil student.instance_variable_get(:@_memoized_seniority)
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.14.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: 2015-12-15 00:00:00.000000000 Z
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.4.8
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: