tacky 0.5.1 → 0.5.2
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 +4 -4
- data/.rubocop.yml +2 -2
- data/lib/tacky.rb +4 -2
- data/tacky.gemspec +1 -1
- data/test/test_tacky.rb +19 -4
- 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: d5169130c14020b608d8c321ecd838a5593c61b6c43494c69cad647611313d29
|
4
|
+
data.tar.gz: 95583567be0ac82aff2e1af2fbe310b9c4b3cd6bb34bfe75669adb4f734a772c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 371e36840b98444725e97e6ab46080da007e34df15c557c09fcf3727e9b4cde6edd8b142ab773bce3ece3a4b3c16cfbaba52cb3b579498d467fefee66b6aa9c1
|
7
|
+
data.tar.gz: 875cecc83dc3b6b6b8b6b53eab2153adae00aa5f5fffc2c505396466cef25c0a68c1f1668a00e7f90cac95bdd4f3b29719dfcf7ccb75ec3b72007d252350e5b7
|
data/.rubocop.yml
CHANGED
data/lib/tacky.rb
CHANGED
@@ -32,14 +32,16 @@ class Tacky
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def method_missing(*args)
|
35
|
+
maybe = %i[key keyreq]
|
35
36
|
@mutex.synchronize do
|
36
37
|
key = args.dup
|
37
38
|
mtd = args.shift
|
38
39
|
unless @cache.key?(key)
|
39
40
|
params = @origin.method(mtd).parameters
|
41
|
+
reqs = params.count { |p| p[0] == :req }
|
40
42
|
@cache[key] =
|
41
|
-
if params.any? { |p| p[0]
|
42
|
-
@origin.__send__(mtd, *args[0
|
43
|
+
if params.any? { |p| maybe.include?(p[0]) } && args.size > reqs
|
44
|
+
@origin.__send__(mtd, *args[0..-2], **args.last) do |*a|
|
43
45
|
yield(*a) if block_given?
|
44
46
|
end
|
45
47
|
else
|
data/tacky.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
|
9
9
|
s.required_ruby_version = '>= 2.3'
|
10
10
|
s.name = 'tacky'
|
11
|
-
s.version = '0.5.
|
11
|
+
s.version = '0.5.2'
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.summary = 'Primitive Object Memoization for Ruby'
|
14
14
|
s.description =
|
data/test/test_tacky.rb
CHANGED
@@ -23,12 +23,14 @@ class TackyTest < Minitest::Test
|
|
23
23
|
|
24
24
|
def test_passes_hash_args
|
25
25
|
foo = Object.new
|
26
|
-
def foo.value(
|
27
|
-
rand(
|
26
|
+
def foo.value(one, two:)
|
27
|
+
rand(one + two)
|
28
28
|
end
|
29
29
|
bar = Tacky.new(foo)
|
30
|
-
first = bar.value(42,
|
31
|
-
assert_equal(bar.value(42,
|
30
|
+
first = bar.value(42, two: 1)
|
31
|
+
assert_equal(bar.value(42, two: 1), first)
|
32
|
+
refute_equal(bar.value(777, two: 1), first)
|
33
|
+
refute_equal(bar.value(42, two: 555), first)
|
32
34
|
end
|
33
35
|
|
34
36
|
def test_passes_default_hash_args
|
@@ -39,6 +41,18 @@ class TackyTest < Minitest::Test
|
|
39
41
|
bar = Tacky.new(foo)
|
40
42
|
first = bar.value(42)
|
41
43
|
assert_equal(bar.value(42), first)
|
44
|
+
refute_equal(bar.value(0), first)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_passes_one_default_hash_args
|
48
|
+
foo = Object.new
|
49
|
+
def foo.value(_one: 42)
|
50
|
+
rand(100)
|
51
|
+
end
|
52
|
+
bar = Tacky.new(foo)
|
53
|
+
first = bar.value
|
54
|
+
assert_equal(bar.value, first)
|
55
|
+
refute_equal(bar.value(_one: 44), first)
|
42
56
|
end
|
43
57
|
|
44
58
|
def test_passes_default_args
|
@@ -49,6 +63,7 @@ class TackyTest < Minitest::Test
|
|
49
63
|
bar = Tacky.new(foo)
|
50
64
|
first = bar.value
|
51
65
|
assert_equal(bar.value, first)
|
66
|
+
refute_equal(bar.value(7), first)
|
52
67
|
end
|
53
68
|
|
54
69
|
def test_deep_caching
|