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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19d56d7272a88d0af05fdf1a22a826fc98e7d71f3205c962884c502b86487ac5
4
- data.tar.gz: 570d9b1a70f86d9787856a7dfc4d5843d5b43ff9835a1be3f65fcdfb4f557bf8
3
+ metadata.gz: d5169130c14020b608d8c321ecd838a5593c61b6c43494c69cad647611313d29
4
+ data.tar.gz: 95583567be0ac82aff2e1af2fbe310b9c4b3cd6bb34bfe75669adb4f734a772c
5
5
  SHA512:
6
- metadata.gz: ac16193c8a93e90096f3864a5b52032efb6123a06044ca23fe552311135b137ee091cb769def25d6b9dab668b3102b2bdb384bf1e666ec965ae655433c553cb8
7
- data.tar.gz: 388dffe5ca6a6d70ea33ff47ad7fa96b39c19da463176e8c907859b8809d124ae5ccf3d38a01144f2ec0dbd21535384e5c2fb3b095fc18cc4ae5ae71e898d9c3
6
+ metadata.gz: 371e36840b98444725e97e6ab46080da007e34df15c557c09fcf3727e9b4cde6edd8b142ab773bce3ece3a4b3c16cfbaba52cb3b579498d467fefee66b6aa9c1
7
+ data.tar.gz: 875cecc83dc3b6b6b8b6b53eab2153adae00aa5f5fffc2c505396466cef25c0a68c1f1668a00e7f90cac95bdd4f3b29719dfcf7ccb75ec3b72007d252350e5b7
data/.rubocop.yml CHANGED
@@ -29,9 +29,9 @@ Metrics/MethodLength:
29
29
  Metrics/ClassLength:
30
30
  Max: 180
31
31
  Metrics/CyclomaticComplexity:
32
- Max: 10
32
+ Max: 15
33
33
  Metrics/PerceivedComplexity:
34
- Max: 10
34
+ Max: 15
35
35
  Metrics/ParameterLists:
36
36
  Max: 10
37
37
  Layout/ParameterAlignment:
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] == :keyreq }
42
- @origin.__send__(mtd, *args[0...-1], **args.last) do |*a|
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.1'
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(_one, _two:)
27
- rand(100)
26
+ def foo.value(one, two:)
27
+ rand(one + two)
28
28
  end
29
29
  bar = Tacky.new(foo)
30
- first = bar.value(42, _two: 1)
31
- assert_equal(bar.value(42, _two: 1), first)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tacky
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko