memoist 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/memoist.rb +1 -1
- data/lib/memoist/version.rb +1 -1
- data/test/memoist_test.rb +42 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae4871b19ddf0826d00aed6706f6d4e18e87b1fc
|
4
|
+
data.tar.gz: 9f51de9a63090ec5e42ec3e17ca3188776f537a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d53081c9d2c4041458aedd80ef01f4ac4933882edb08315081a8ec7846ef9dcad9730a8a21458a78ad78bc913c94ca6fd06f55376706b1c0ead43254090b91
|
7
|
+
data.tar.gz: 5ae1ffcf79b52f2d9b52aa59d66eeeaf7f1b1ad80a247d4549ac902ef1e2e7bdcc70c6429974faba32f085d5a5b0d859d5288927a043528718ce00d7c0ad0f55
|
data/lib/memoist.rb
CHANGED
@@ -31,7 +31,7 @@ module Memoist
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.extract_reload!(method, args)
|
34
|
-
if args.length == method.arity + 1 && (args.last == true || args.last == :reload)
|
34
|
+
if args.length == method.arity.abs + 1 && (args.last == true || args.last == :reload)
|
35
35
|
reload = args.pop
|
36
36
|
end
|
37
37
|
reload
|
data/lib/memoist/version.rb
CHANGED
data/test/memoist_test.rb
CHANGED
@@ -70,6 +70,26 @@ class MemoistTest < Minitest::Unit::TestCase
|
|
70
70
|
|
71
71
|
memoize :name, :age
|
72
72
|
|
73
|
+
def sleep(hours = 8)
|
74
|
+
@counter.call(:sleep)
|
75
|
+
hours
|
76
|
+
end
|
77
|
+
memoize :sleep
|
78
|
+
|
79
|
+
def sleep_calls
|
80
|
+
@counter.count(:sleep)
|
81
|
+
end
|
82
|
+
|
83
|
+
def update_attributes(options = {})
|
84
|
+
@counter.call(:update_attributes)
|
85
|
+
true
|
86
|
+
end
|
87
|
+
memoize :update_attributes
|
88
|
+
|
89
|
+
def update_attributes_calls
|
90
|
+
@counter.count(:update_attributes)
|
91
|
+
end
|
92
|
+
|
73
93
|
protected
|
74
94
|
|
75
95
|
def memoize_protected_test
|
@@ -167,6 +187,28 @@ class MemoistTest < Minitest::Unit::TestCase
|
|
167
187
|
assert_equal 1, @person.name_calls
|
168
188
|
end
|
169
189
|
|
190
|
+
def test_memoize_with_optional_arguments
|
191
|
+
assert_equal 4, @person.sleep(4)
|
192
|
+
assert_equal 1, @person.sleep_calls
|
193
|
+
|
194
|
+
3.times { assert_equal 4, @person.sleep(4) }
|
195
|
+
assert_equal 1, @person.sleep_calls
|
196
|
+
|
197
|
+
3.times { assert_equal 4, @person.sleep(4, :reload) }
|
198
|
+
assert_equal 4, @person.sleep_calls
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_memoize_with_options_hash
|
202
|
+
assert_equal true, @person.update_attributes(:age => 21, :name => 'James')
|
203
|
+
assert_equal 1, @person.update_attributes_calls
|
204
|
+
|
205
|
+
3.times { assert_equal true, @person.update_attributes(:age => 21, :name => 'James') }
|
206
|
+
assert_equal 1, @person.update_attributes_calls
|
207
|
+
|
208
|
+
3.times { assert_equal true, @person.update_attributes({:age => 21, :name => 'James'}, :reload) }
|
209
|
+
assert_equal 4, @person.update_attributes_calls
|
210
|
+
end
|
211
|
+
|
170
212
|
def test_memoization_with_punctuation
|
171
213
|
assert_equal true, @person.name?
|
172
214
|
|
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.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Peek
|
@@ -19,7 +19,7 @@ authors:
|
|
19
19
|
autorequire:
|
20
20
|
bindir: bin
|
21
21
|
cert_chain: []
|
22
|
-
date: 2014-
|
22
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: bundler
|