tacky 0.5.0 → 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: 66e070784bf3eab59a930f0d63a5f910fb33f0bd6642c8d2148ea96adef88c9c
4
- data.tar.gz: 94e8f05a030e86e042f839bb3f14c9bd10f193af4187ed83a7c54f4e94ac59c1
3
+ metadata.gz: d5169130c14020b608d8c321ecd838a5593c61b6c43494c69cad647611313d29
4
+ data.tar.gz: 95583567be0ac82aff2e1af2fbe310b9c4b3cd6bb34bfe75669adb4f734a772c
5
5
  SHA512:
6
- metadata.gz: a4ca0db0df2352b30efa323b54ec6145a99cba13a57fa3d84c44d56ab6a949b97a664b100031b102d56bc935129275bccbe3e7c225074d609e7148da0ded2f8a
7
- data.tar.gz: acb6474481c989d587516c2fd6a10220f2143e4c5eccd2d5eb3bec9b6442fc5b76e5628a3afa07e4e495feb57776fa0935bd3cdd37e8b618acacc34a4d644326
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,26 @@ class Tacky
32
32
  end
33
33
 
34
34
  def method_missing(*args)
35
+ maybe = %i[key keyreq]
35
36
  @mutex.synchronize do
36
- unless @cache.key?(args)
37
- @cache[args] = @origin.__send__(*args) do |*a|
38
- yield(*a) if block_given?
39
- end
40
- @cache[args] = Tacky.new(@cache[args], deep: @deep) if @deep && STOP.none? { |t| @cache[args].is_a?(t) }
37
+ key = args.dup
38
+ mtd = args.shift
39
+ unless @cache.key?(key)
40
+ params = @origin.method(mtd).parameters
41
+ reqs = params.count { |p| p[0] == :req }
42
+ @cache[key] =
43
+ if params.any? { |p| maybe.include?(p[0]) } && args.size > reqs
44
+ @origin.__send__(mtd, *args[0..-2], **args.last) do |*a|
45
+ yield(*a) if block_given?
46
+ end
47
+ else
48
+ @origin.__send__(mtd, *args) do |*a|
49
+ yield(*a) if block_given?
50
+ end
51
+ end
52
+ @cache[key] = Tacky.new(@cache[key], deep: @deep) if @deep && STOP.none? { |t| @cache[key].is_a?(t) }
41
53
  end
42
- @cache[args]
54
+ @cache[key]
43
55
  end
44
56
  end
45
57
 
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.0'
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
@@ -21,6 +21,51 @@ class TackyTest < Minitest::Test
21
21
  assert_equal(bar.value, first)
22
22
  end
23
23
 
24
+ def test_passes_hash_args
25
+ foo = Object.new
26
+ def foo.value(one, two:)
27
+ rand(one + two)
28
+ end
29
+ bar = Tacky.new(foo)
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)
34
+ end
35
+
36
+ def test_passes_default_hash_args
37
+ foo = Object.new
38
+ def foo.value(_one, _two: 42)
39
+ rand(100)
40
+ end
41
+ bar = Tacky.new(foo)
42
+ first = bar.value(42)
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)
56
+ end
57
+
58
+ def test_passes_default_args
59
+ foo = Object.new
60
+ def foo.value(_one = 42)
61
+ rand(100)
62
+ end
63
+ bar = Tacky.new(foo)
64
+ first = bar.value
65
+ assert_equal(bar.value, first)
66
+ refute_equal(bar.value(7), first)
67
+ end
68
+
24
69
  def test_deep_caching
25
70
  foo = Object.new
26
71
  def foo.child
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.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko