memoist 0.11.0 → 0.12.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 +1 -4
- data/README.md +20 -1
- data/lib/memoist.rb +2 -2
- data/lib/memoist/version.rb +1 -1
- data/test/memoist_test.rb +0 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2940374d92fdc408f67414dc6aefaee449b0722
|
4
|
+
data.tar.gz: 1e695236b23a8a12790732c8f00fbe0bf7251fda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 714ba49dd47d39cfaef3d19ff8e0d56e115d059760016fd43a6d6379701422e58fb10a8b6481972d4108fc7e6db35cf82339a494dcff810f743363db6de757e8
|
7
|
+
data.tar.gz: 9a645417282d73779cdfabaad7222b6b5bc769e9d1a0968ffa51f901eb66ce3bdbadb715398a7c7853ad4607da3c63fffad3b97b684b22b69740612d47712c08
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -62,6 +62,25 @@ You can also memoize class methods.
|
|
62
62
|
|
63
63
|
end
|
64
64
|
|
65
|
+
When a sub-class overrides one of its parent's methods and you need to memoize both.
|
66
|
+
Then you can use the `:identifier` parameter in order to help _Memoist_ distinguish between the two.
|
67
|
+
|
68
|
+
class Clock
|
69
|
+
extend Memoist
|
70
|
+
def now
|
71
|
+
"The time now is #{Time.now.hour} o'clock and #{Time.now.min} minutes"
|
72
|
+
end
|
73
|
+
memoize :now
|
74
|
+
end
|
75
|
+
|
76
|
+
class AccurateClock < Clock
|
77
|
+
extend Memoist
|
78
|
+
def now
|
79
|
+
"#{super} and #{Time.now.sec} seconds"
|
80
|
+
end
|
81
|
+
memoize :now, :identifier => :accurate_clock
|
82
|
+
end
|
83
|
+
|
65
84
|
|
66
85
|
Reload
|
67
86
|
------
|
@@ -101,7 +120,7 @@ Everyone who contributed to it in the rails repository.
|
|
101
120
|
Contributing
|
102
121
|
============
|
103
122
|
|
104
|
-
1. Fork it ( http://github.com
|
123
|
+
1. Fork it ( http://github.com/*my-github-username*/memoist/fork )
|
105
124
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
125
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
107
126
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/memoist.rb
CHANGED
@@ -96,7 +96,8 @@ module Memoist
|
|
96
96
|
include InstanceMethods
|
97
97
|
|
98
98
|
if method_defined?(unmemoized_method)
|
99
|
-
|
99
|
+
warn "Already memoized #{method_name}"
|
100
|
+
return
|
100
101
|
end
|
101
102
|
alias_method unmemoized_method, method_name
|
102
103
|
|
@@ -197,5 +198,4 @@ module Memoist
|
|
197
198
|
method_names.length == 1 ? method_names.first : method_names
|
198
199
|
end
|
199
200
|
|
200
|
-
class AlreadyMemoizedError < RuntimeError; end
|
201
201
|
end
|
data/lib/memoist/version.rb
CHANGED
data/test/memoist_test.rb
CHANGED
@@ -330,18 +330,6 @@ class MemoistTest < Minitest::Unit::TestCase
|
|
330
330
|
assert_equal 2, company.sales_tax_calls
|
331
331
|
end
|
332
332
|
|
333
|
-
def test_double_memoization
|
334
|
-
assert_raises(Memoist::AlreadyMemoizedError) { Person.memoize :name }
|
335
|
-
person = Person.new
|
336
|
-
person.extend Memoist
|
337
|
-
assert_raises(Memoist::AlreadyMemoizedError) { person.memoize :name }
|
338
|
-
|
339
|
-
company = Company.new
|
340
|
-
company.extend Memoist
|
341
|
-
company.memoize :name
|
342
|
-
assert_raises(Memoist::AlreadyMemoizedError) { company.memoize :name }
|
343
|
-
end
|
344
|
-
|
345
333
|
def test_double_memoization_with_identifier
|
346
334
|
Person.memoize :name, :identifier => :again
|
347
335
|
end
|
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.12.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:
|
22
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
25
25
|
name: bundler
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.4.5
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: memoize methods invocation
|