tacky 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/tacky.rb +3 -1
- data/tacky.gemspec +1 -1
- data/test/test_tacky.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f359078e7fe3507487d2882ca7b2e4b258ceb1f2ccbbe7b037de55a96f4e4270
|
4
|
+
data.tar.gz: d3c24621a7e5931b33b9ae06d1e77739a266779b75b67ffc501b1b53b98b253c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4adb311efb6ce79791a2bf7b3516ebfb859f99fa8fde8787c6ce79383c58912b7075c0ed8d2195a05b8c216dbe72f7df26e6f47f6875bb4c2d80edb5e015c9cd
|
7
|
+
data.tar.gz: 0fb6b8402435241da058421978d4dc073b8c16d10b621f65128267fbede32df300527fa79bf546b234ffe3c9eafc5203fbfd6cc8c2821bb5ab8a9f1e07037740
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[![Build Status](https://travis-ci.org/yegor256/tacky.svg)](https://travis-ci.org/yegor256/tacky)
|
8
8
|
[![Build status](https://ci.appveyor.com/api/projects/status/e61qudqccs0fu8xt?svg=true)](https://ci.appveyor.com/project/yegor256/tacky)
|
9
9
|
[![Gem Version](https://badge.fury.io/rb/tacky.svg)](http://badge.fury.io/rb/tacky)
|
10
|
-
[![Maintainability](https://api.codeclimate.com/v1/badges/
|
10
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/224939b58aa606fdd56c/maintainability)](https://codeclimate.com/github/yegor256/tacky/maintainability)
|
11
11
|
[![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/tacky/master/frames)
|
12
12
|
|
13
13
|
[![Hits-of-Code](https://hitsofcode.com/github/yegor256/tacky)](https://hitsofcode.com/view/github/yegor256/tacky)
|
@@ -26,7 +26,17 @@ require 'tacky'
|
|
26
26
|
obj = Tacky.new(obj)
|
27
27
|
```
|
28
28
|
|
29
|
-
That's it
|
29
|
+
That's it, all method calls will be cached.
|
30
|
+
|
31
|
+
If you want all methods of everything your methods return be cached, you
|
32
|
+
need to use "deep" caching:
|
33
|
+
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
obj = Tacky.new(obj, deep: true)
|
37
|
+
```
|
38
|
+
|
39
|
+
`Tacky` is thread-safe.
|
30
40
|
|
31
41
|
## How to contribute
|
32
42
|
|
data/lib/tacky.rb
CHANGED
@@ -34,9 +34,10 @@
|
|
34
34
|
class Tacky
|
35
35
|
undef_method :send
|
36
36
|
|
37
|
-
def initialize(origin)
|
37
|
+
def initialize(origin, deep: false)
|
38
38
|
@origin = origin
|
39
39
|
@cache = {}
|
40
|
+
@deep = deep
|
40
41
|
@mutex = Mutex.new
|
41
42
|
end
|
42
43
|
|
@@ -46,6 +47,7 @@ class Tacky
|
|
46
47
|
@cache[args] = @origin.__send__(*args) do |*a|
|
47
48
|
yield(*a) if block_given?
|
48
49
|
end
|
50
|
+
@cache[args] = Tacky.new(@cache[args]) if @deep
|
49
51
|
end
|
50
52
|
@cache[args]
|
51
53
|
end
|
data/tacky.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.rubygems_version = '2.3.3'
|
32
32
|
s.required_ruby_version = '>=2.3'
|
33
33
|
s.name = 'tacky'
|
34
|
-
s.version = '0.
|
34
|
+
s.version = '0.3.0'
|
35
35
|
s.license = 'MIT'
|
36
36
|
s.summary = 'Primitive Object Memoization for Ruby'
|
37
37
|
s.description = 'Decorate your existing Ruby object with Tacky
|
data/test/test_tacky.rb
CHANGED
@@ -39,4 +39,18 @@ class TackyTest < Minitest::Test
|
|
39
39
|
first = bar.value
|
40
40
|
assert(bar.value == first)
|
41
41
|
end
|
42
|
+
|
43
|
+
def test_deep_caching
|
44
|
+
foo = Object.new
|
45
|
+
def foo.child
|
46
|
+
bar = Object.new
|
47
|
+
def bar.value
|
48
|
+
rand(100)
|
49
|
+
end
|
50
|
+
bar
|
51
|
+
end
|
52
|
+
bar = Tacky.new(foo, deep: true)
|
53
|
+
first = bar.child.value
|
54
|
+
assert(bar.child.value == first)
|
55
|
+
end
|
42
56
|
end
|