decoratable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/decoratable.gemspec +1 -1
- data/lib/decoratable/memoizable.rb +12 -4
- data/test/decoratable/memoizable_test.rb +10 -1
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0090c17ce4e8f9334a6bdebfb059b47fb7c7350d'
|
4
|
+
data.tar.gz: 185f96d6a0f5402dda2d66eb913f731ce1944a39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae18c7e17a48897596a56bdcc3f8e97ccf83d45d34edbd3ee7bea5aeb7f24b66a6eaf3bde36bc7ae726c299fe0c20e5ee09022d179ecb4ef549caa15b33186a8
|
7
|
+
data.tar.gz: 6d6c3293e01975fe16a305fc4a9494a272c82fec94511eabe83b663ee63e122974c9361e39f992412c803fc7000d2a7bd773d52f9dfe390edb57b3270b87f80b
|
data/decoratable.gemspec
CHANGED
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "decoratable"
|
6
|
-
spec.version = "0.0.
|
6
|
+
spec.version = "0.0.4"
|
7
7
|
spec.authors = ["ecin"]
|
8
8
|
spec.email = ["ecin@copypastel.com"]
|
9
9
|
spec.description = "Decorate your methods."
|
@@ -3,13 +3,21 @@ require "decoratable"
|
|
3
3
|
module Memoizable
|
4
4
|
extend Decoratable
|
5
5
|
|
6
|
+
MEMOIZABLE_CACHE_KEY = :"@memoizable_cache"
|
7
|
+
|
6
8
|
def memoizable
|
7
|
-
|
9
|
+
if instance_variable_defined?(MEMOIZABLE_CACHE_KEY)
|
10
|
+
cache = instance_variable_get(MEMOIZABLE_CACHE_KEY)
|
11
|
+
else
|
12
|
+
cache = instance_variable_set(MEMOIZABLE_CACHE_KEY, Hash.new)
|
13
|
+
end
|
14
|
+
|
15
|
+
key = __decorated_method__.name.to_sym
|
8
16
|
|
9
|
-
if
|
10
|
-
|
17
|
+
if cache.has_key?(key)
|
18
|
+
cache[key]
|
11
19
|
else
|
12
|
-
|
20
|
+
cache[key] = yield
|
13
21
|
end
|
14
22
|
end
|
15
23
|
end
|
@@ -13,16 +13,25 @@ describe Memoizable do
|
|
13
13
|
@count ||= 0
|
14
14
|
@count += 1
|
15
15
|
end
|
16
|
+
|
17
|
+
memoizable
|
18
|
+
def scream!
|
19
|
+
"BOO!"
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
@object = klass.new
|
19
24
|
end
|
20
25
|
|
21
|
-
it "memoizes a
|
26
|
+
it "memoizes a method's return value" do
|
22
27
|
3.times { @object.call }
|
23
28
|
|
24
29
|
# If method was memoized, the counter shouldn't have incremented
|
25
30
|
@object.call.must_equal 1
|
26
31
|
end
|
27
32
|
|
33
|
+
it "works with methods that have punctuation marks" do
|
34
|
+
3.times { @object.scream! }
|
35
|
+
end
|
36
|
+
|
28
37
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: decoratable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ecin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 10.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 10.0.0
|
55
55
|
description: Decorate your methods.
|
@@ -59,7 +59,7 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- .travis.yml
|
62
|
+
- ".travis.yml"
|
63
63
|
- Gemfile
|
64
64
|
- README.rdoc
|
65
65
|
- Rakefile
|
@@ -92,17 +92,17 @@ require_paths:
|
|
92
92
|
- lib
|
93
93
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- -
|
95
|
+
- - ">="
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: '0'
|
98
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
requirements: []
|
104
104
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
105
|
+
rubygems_version: 2.6.12
|
106
106
|
signing_key:
|
107
107
|
specification_version: 4
|
108
108
|
summary: Easily define decorations for your methods. Put a bow on it.
|