mize 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9eddd37dbe3b1119706e25a105cfd49256c42a401ded5ddba30d479c36ba93b5
4
- data.tar.gz: 936a9c5c05083e2f30c1dd1f007b65de80ed2cfb5019a39db948329d6529f5a1
3
+ metadata.gz: 517d9cb2997631d2645b96f8c54c2b9390370146aa1164f6c4acdf36ec99475a
4
+ data.tar.gz: e9a36341149d75c25156496b2a4a630ad561aaa620dd2428ecce38cb33786cea
5
5
  SHA512:
6
- metadata.gz: df782c8ad0f19a9fc3deb9fb7131d5be1f0eb917d25820396e0e98a06ec7c3acda41f3345c4492dac770130d69bbd8099e58763db5edf5a7ff3d38f6fc9a2ff5
7
- data.tar.gz: 44395da5d9a27704881ae98d3b029cac200e4d29af29b9cda24cd2b304b7254be7a159032a53aa0deb46830aaee790a06252e220c9ef2beb2eaf5a34083f43d1
6
+ metadata.gz: 1a9c6cca1a2bbc599b153c8cdcb8b6fdfe80cadd591d269d7e6a70db666edec61651fc61f18e0e9b24d61a4cfc0489b096844eec3cf29c3ce3bee5d7c89c11cc
7
+ data.tar.gz: '058e70026c3535d00bcaecd775e17c04bfcb0cf70c836f88624080f79668ed79b0201b6b7e5bf5f76d33d5e3a2b20d8bee27e5dd6e252a6db76a75f15e3581a8'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.6.0
data/lib/mize/memoize.rb CHANGED
@@ -31,11 +31,11 @@ module Mize
31
31
  class << self
32
32
  private
33
33
 
34
- def compute_result(method_id, orig_method, key, context, args, freeze)
34
+ def compute_result(method_id, orig_method, key, context, args, kargs, freeze)
35
35
  result = orig_method.bind(context).call(*args)
36
36
  if $DEBUG
37
37
  warn "#{context.class} cached method "\
38
- "#{method_id}(#{args.inspect unless args.empty?}) = "\
38
+ "#{method_id}(#{[ args, kargs ].inspect unless args.size + kargs.size == 0}) = "\
39
39
  "#{result.inspect} [#{__id__}]"
40
40
  end
41
41
  freeze and result.freeze rescue nil
@@ -65,14 +65,14 @@ module Mize
65
65
  method_id = method_id.to_s.to_sym
66
66
  memoize_apply_visibility method_id do
67
67
  orig_method = instance_method(method_id)
68
- __send__(:define_method, method_id) do |*args|
68
+ __send__(:define_method, method_id) do |*args, **kargs|
69
69
  function or mc = __mize_cache__
70
- key = build_key(method_id, *args)
70
+ key = build_key(method_id, *args, **kargs)
71
71
  if mc.exist?(key)
72
72
  mc.read(key)
73
73
  else
74
74
  result = Mize::Memoize.send(
75
- :compute_result, method_id, orig_method, key, self, args, freeze
75
+ :compute_result, method_id, orig_method, key, self, args, kargs, freeze
76
76
  )
77
77
  if store_nil || !result.nil?
78
78
  mc.write(key, result)
data/lib/mize/railtie.rb CHANGED
@@ -5,4 +5,3 @@ module Mize
5
5
  end
6
6
  end
7
7
  end
8
-
data/lib/mize/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Mize
2
2
  # Mize version
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/mize.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: mize 0.5.0 ruby lib
2
+ # stub: mize 0.6.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mize".freeze
6
- s.version = "0.5.0".freeze
6
+ s.version = "0.6.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-07-15"
11
+ s.date = "2024-07-25"
12
12
  s.description = "Library that provides memoziation for methods and functions for Ruby.".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.extra_rdoc_files = ["README.md".freeze, "lib/mize.rb".freeze, "lib/mize/cache_methods.rb".freeze, "lib/mize/cache_protocol.rb".freeze, "lib/mize/configure.rb".freeze, "lib/mize/default_cache.rb".freeze, "lib/mize/global_clear.rb".freeze, "lib/mize/memoize.rb".freeze, "lib/mize/railtie.rb".freeze, "lib/mize/reload.rb".freeze, "lib/mize/version.rb".freeze]
@@ -17,13 +17,13 @@ Gem::Specification.new do |s|
17
17
  s.licenses = ["MIT".freeze]
18
18
  s.rdoc_options = ["--title".freeze, "Mize - Library that provides memoziation for methods and functions".freeze, "--main".freeze, "README.md".freeze]
19
19
  s.required_ruby_version = Gem::Requirement.new(">= 2".freeze)
20
- s.rubygems_version = "3.5.11".freeze
20
+ s.rubygems_version = "3.5.16".freeze
21
21
  s.summary = "Library that provides memoziation for methods and functions".freeze
22
22
  s.test_files = ["spec/mize/global_clear_spec.rb".freeze, "spec/mize/memoize_method_spec.rb".freeze, "spec/mize/memoize_reload_spec.rb".freeze, "spec/mize/version_spec.rb".freeze, "spec/spec_helper.rb".freeze]
23
23
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.16.0".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.16.1".freeze])
27
27
  s.add_development_dependency(%q<rake>.freeze, [">= 0".freeze])
28
28
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
@@ -27,6 +27,12 @@ class FooBar
27
27
  end
28
28
  memoize method: :foo
29
29
 
30
+ def foo2(arg: 22)
31
+ @@foo2 ||= arg
32
+ @@foo2 += 1
33
+ end
34
+ memoize method: :foo2
35
+
30
36
  def footsie(*a)
31
37
  @@footsie ||= 0
32
38
  @@footsie += 1
@@ -40,6 +46,12 @@ class FooBar
40
46
  end
41
47
  memoize function: :bar
42
48
 
49
+ def bar2(arg: 22)
50
+ @@bar2 ||= arg
51
+ @@bar2 += 1
52
+ end
53
+ memoize function: :bar2
54
+
43
55
  def foo_nil_stored(*a)
44
56
  @@foo_nil_stored ||= 0
45
57
  @@foo_nil_stored += 1
@@ -101,6 +113,29 @@ describe Mize do
101
113
  expect(fb2.__send__(:__mize_cache__)).not_to be_empty
102
114
  end
103
115
 
116
+ it 'can cache methods with kargs' do
117
+ expect(fb1.__send__(:__mize_cache__)).to be_empty
118
+ expect(fb2.__send__(:__mize_cache__)).to be_empty
119
+ expect(fb1.foo2()).to eq 23
120
+ expect(fb2.foo2()).to eq 24
121
+ expect(fb1.foo2(arg: 123)).to eq 25
122
+ expect(fb2.foo2(arg: 123)).to eq 26
123
+ expect(fb1.foo2()).to eq 23
124
+ expect(fb2.foo2()).to eq 24
125
+ fb1.mize_cache_clear
126
+ fb2.mize_cache_clear
127
+ expect(fb1.__send__(:__mize_cache__)).to be_empty
128
+ expect(fb2.__send__(:__mize_cache__)).to be_empty
129
+ expect(fb1.foo2()).to eq 27
130
+ expect(fb2.foo2()).to eq 28
131
+ expect(fb1.foo2()).to eq 27
132
+ expect(fb2.foo2()).to eq 28
133
+ expect(fb1.foo2(arg: 123)).to eq 29
134
+ expect(fb2.foo2(arg: 123)).to eq 30
135
+ expect(fb1.__send__(:__mize_cache__)).not_to be_empty
136
+ expect(fb2.__send__(:__mize_cache__)).not_to be_empty
137
+ end
138
+
104
139
  it 'can cache protected methods' do
105
140
  expect(fb1.__send__(:__mize_cache__)).to be_empty
106
141
  expect(fb2.__send__(:__mize_cache__)).to be_empty
@@ -189,6 +224,20 @@ describe Mize do
189
224
  expect(FooBar.__send__(:__mize_cache__)).not_to be_empty
190
225
  end
191
226
 
227
+ it 'can cache functions with kargs' do
228
+ expect(FooBar.__send__(:__mize_cache__)).to be_empty
229
+ expect(fb1.bar2).to eq 23
230
+ expect(fb2.bar2).to eq 23
231
+ expect(fb1.bar2(arg: 123)).to eq 24
232
+ expect(fb2.bar2(arg: 123)).to eq 24
233
+ expect(fb1.bar2).to eq 23
234
+ expect(fb2.bar2).to eq 23
235
+ FooBar.mize_cache_clear
236
+ expect(fb1.bar2).to eq 25
237
+ expect(fb2.bar2).to eq 25
238
+ expect(FooBar.__send__(:__mize_cache__)).not_to be_empty
239
+ end
240
+
192
241
  it 'can cache private functions' do
193
242
  expect(FooBar.__send__(:__mize_cache__)).to be_empty
194
243
  expect(fb1.__send__(:baz, 1, 2)).to eq 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mize
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-15 00:00:00.000000000 Z
11
+ date: 2024-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.16.0
19
+ version: 1.16.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.16.0
26
+ version: 1.16.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.5.11
165
+ rubygems_version: 3.5.16
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Library that provides memoziation for methods and functions