memoist 0.10.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6cbdccba6864dd468cbc605eea82d6b6660e17aa
4
- data.tar.gz: eb288efc956474d2c738130e1ee3e58140331df7
3
+ metadata.gz: ae4871b19ddf0826d00aed6706f6d4e18e87b1fc
4
+ data.tar.gz: 9f51de9a63090ec5e42ec3e17ca3188776f537a7
5
5
  SHA512:
6
- metadata.gz: 2de14221820dc0c53f805e441a6a6b3e85fac5ae3da819d9e3accab2a485ab8399af8e2b852ea121d533831e0204b43774660c665a3bd054c13a40c9d6d028d5
7
- data.tar.gz: da1e5080bd827b606c79e395f4f089a8b2df4d8ca7a069b8032f7532bf35c1a3349f8659b98e1ed4a9ae45ea50152bbf1d9d79f40b9361492e1be0d92b13cba5
6
+ metadata.gz: e2d53081c9d2c4041458aedd80ef01f4ac4933882edb08315081a8ec7846ef9dcad9730a8a21458a78ad78bc913c94ca6fd06f55376706b1c0ead43254090b91
7
+ data.tar.gz: 5ae1ffcf79b52f2d9b52aa59d66eeeaf7f1b1ad80a247d4549ac902ef1e2e7bdcc70c6429974faba32f085d5a5b0d859d5288927a043528718ce00d7c0ad0f55
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Memoist
2
- VERSION = "0.10.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -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.10.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-08-13 00:00:00.000000000 Z
22
+ date: 2014-10-10 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: bundler