tacky 0.5.0 → 0.5.1

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: 19d56d7272a88d0af05fdf1a22a826fc98e7d71f3205c962884c502b86487ac5
4
+ data.tar.gz: 570d9b1a70f86d9787856a7dfc4d5843d5b43ff9835a1be3f65fcdfb4f557bf8
5
5
  SHA512:
6
- metadata.gz: a4ca0db0df2352b30efa323b54ec6145a99cba13a57fa3d84c44d56ab6a949b97a664b100031b102d56bc935129275bccbe3e7c225074d609e7148da0ded2f8a
7
- data.tar.gz: acb6474481c989d587516c2fd6a10220f2143e4c5eccd2d5eb3bec9b6442fc5b76e5628a3afa07e4e495feb57776fa0935bd3cdd37e8b618acacc34a4d644326
6
+ metadata.gz: ac16193c8a93e90096f3864a5b52032efb6123a06044ca23fe552311135b137ee091cb769def25d6b9dab668b3102b2bdb384bf1e666ec965ae655433c553cb8
7
+ data.tar.gz: 388dffe5ca6a6d70ea33ff47ad7fa96b39c19da463176e8c907859b8809d124ae5ccf3d38a01144f2ec0dbd21535384e5c2fb3b095fc18cc4ae5ae71e898d9c3
data/lib/tacky.rb CHANGED
@@ -33,13 +33,23 @@ class Tacky
33
33
 
34
34
  def method_missing(*args)
35
35
  @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) }
36
+ key = args.dup
37
+ mtd = args.shift
38
+ unless @cache.key?(key)
39
+ params = @origin.method(mtd).parameters
40
+ @cache[key] =
41
+ if params.any? { |p| p[0] == :keyreq }
42
+ @origin.__send__(mtd, *args[0...-1], **args.last) do |*a|
43
+ yield(*a) if block_given?
44
+ end
45
+ else
46
+ @origin.__send__(mtd, *args) do |*a|
47
+ yield(*a) if block_given?
48
+ end
49
+ end
50
+ @cache[key] = Tacky.new(@cache[key], deep: @deep) if @deep && STOP.none? { |t| @cache[key].is_a?(t) }
41
51
  end
42
- @cache[args]
52
+ @cache[key]
43
53
  end
44
54
  end
45
55
 
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.1'
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,36 @@ 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(100)
28
+ end
29
+ bar = Tacky.new(foo)
30
+ first = bar.value(42, _two: 1)
31
+ assert_equal(bar.value(42, _two: 1), first)
32
+ end
33
+
34
+ def test_passes_default_hash_args
35
+ foo = Object.new
36
+ def foo.value(_one, _two: 42)
37
+ rand(100)
38
+ end
39
+ bar = Tacky.new(foo)
40
+ first = bar.value(42)
41
+ assert_equal(bar.value(42), first)
42
+ end
43
+
44
+ def test_passes_default_args
45
+ foo = Object.new
46
+ def foo.value(_one = 42)
47
+ rand(100)
48
+ end
49
+ bar = Tacky.new(foo)
50
+ first = bar.value
51
+ assert_equal(bar.value, first)
52
+ end
53
+
24
54
  def test_deep_caching
25
55
  foo = Object.new
26
56
  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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko