mize 0.4.1 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.all_images.yml +14 -10
- data/.gitignore +2 -0
- data/.utilsrc +2 -2
- data/CHANGES.md +111 -0
- data/Gemfile +0 -2
- data/LICENSE +19 -0
- data/README.md +61 -3
- data/Rakefile +6 -28
- data/VERSION +1 -1
- data/lib/mize/cache_methods.rb +0 -1
- data/lib/mize/cache_protocol.rb +1 -31
- data/lib/mize/configure.rb +3 -0
- data/lib/mize/default_cache.rb +26 -2
- data/lib/mize/memoize.rb +5 -5
- data/lib/mize/railtie.rb +0 -1
- data/lib/mize/version.rb +1 -1
- data/mize.gemspec +14 -26
- data/spec/mize/memoize_method_spec.rb +49 -0
- data/spec/spec_helper.rb +0 -4
- metadata +14 -13
- data/.tool-versions +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9907846af04f5b779a69892b22ffc90f80172a4c0949a28b2b20c8c5d505f3a5
|
4
|
+
data.tar.gz: f18d5f411c014669d5b3a7b7d46a127f0f03522aff97b79cf916b3ee67e58563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2445bf1bc36b723724285132a8ff5f2bb656e80baaf4e3dc2f6813f89d54f11a683526c1425b351d626a24506694060e0cbd7d311cc20fa8e5e3052a2f0f952d
|
7
|
+
data.tar.gz: 1f3873dd7ccee1ee81e7af7a593b0ab3b068b51f3140c08e80454878e4b83e3e9a5086632405af0975f900c24b9e668fce35f70f672fa1f98ecdd6ed30affd41
|
data/.all_images.yml
CHANGED
@@ -1,23 +1,27 @@
|
|
1
1
|
dockerfile: |-
|
2
|
-
RUN apk add --no-cache build-base git
|
3
|
-
RUN
|
4
|
-
|
2
|
+
RUN apk add --no-cache build-base git bash
|
3
|
+
RUN bash <<NUR
|
4
|
+
if [[ "$(ruby -e 'print RUBY_VERSION')" > '3' ]]
|
5
|
+
then
|
6
|
+
gem update --system
|
7
|
+
gem install gem_hadar bundler
|
8
|
+
else
|
9
|
+
gem install gem_hadar
|
10
|
+
gem install bundler -v 2.4.22
|
11
|
+
fi
|
12
|
+
NUR
|
5
13
|
|
6
14
|
script: &script |-
|
7
15
|
echo -e "\e[1m"
|
8
16
|
ruby -v
|
9
17
|
echo -e "\e[0m"
|
10
|
-
bundle
|
11
|
-
bundle
|
18
|
+
bundle install --full-index
|
12
19
|
bundle exec rake spec
|
13
20
|
|
14
21
|
fail_fast: yes
|
15
22
|
|
16
23
|
images:
|
24
|
+
ruby:3.3-alpine: *script
|
25
|
+
ruby:3.2-alpine: *script
|
17
26
|
ruby:3.1-alpine: *script
|
18
27
|
ruby:3.0-alpine: *script
|
19
|
-
ruby:2.7-alpine: *script
|
20
|
-
ruby:2.6-alpine: *script
|
21
|
-
ruby:2.5-alpine: *script
|
22
|
-
ruby:2.4-alpine: *script
|
23
|
-
ruby:2.3-alpine: *script
|
data/.gitignore
CHANGED
data/.utilsrc
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# vim: set ft=ruby:
|
2
2
|
|
3
3
|
search do
|
4
|
-
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
4
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|doc|pkg)\z/
|
5
5
|
skip_files /(\A\.|\.sw[pon]\z|\.(log|fnm|jpg|jpeg|png|pdf|svg)\z|tags|~\z)/i
|
6
6
|
end
|
7
7
|
|
8
8
|
discover do
|
9
|
-
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
|
9
|
+
prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|doc|pkg)\z/
|
10
10
|
skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
|
11
11
|
binary false
|
12
12
|
end
|
data/CHANGES.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Changes
|
2
|
+
|
3
|
+
## 2024-10-17 v0.6.1
|
4
|
+
|
5
|
+
* Remove deprecated Ruby versions:
|
6
|
+
+ Deleted `ruby:2.7-alpine` and `ruby:2.6-alpine` entries
|
7
|
+
* Update `.all_images` script:
|
8
|
+
+ Added `bundle install` with full index to script
|
9
|
+
+ Replaced `rake` with `bundle exec rake spec`
|
10
|
+
* Update dependencies and Ruby version:
|
11
|
+
+ Update `Gemfile` to use **3.5.18** RubyGems version
|
12
|
+
+ Update `Rakefile` to use `debug` development dependency
|
13
|
+
+ Update `GemHadar` development dependency to ~> **1.19**
|
14
|
+
+ Add `debug` development dependency
|
15
|
+
* Add CHANGES.md file
|
16
|
+
* Remove `.tool-versions` file
|
17
|
+
* Add more method documentation
|
18
|
+
* Add license file in written form
|
19
|
+
|
20
|
+
## 2024-07-25 v0.6.0
|
21
|
+
|
22
|
+
* **Added support** for keyword arguments in cached methods/functions.
|
23
|
+
+ Updated `cached_method` method to accept keyword arguments.
|
24
|
+
+ Added test cases for keyword argument handling.
|
25
|
+
|
26
|
+
## 2024-07-15 v0.5.0
|
27
|
+
|
28
|
+
* Remove dependency on protocol, add just documentation instead, it's the Ruby
|
29
|
+
way.
|
30
|
+
* Test on 3.2 and 3.3 rubies as well
|
31
|
+
* Modify gem spec's homepage URL from `http://flori.github.com/#{name}` to `https://github.com/flori/#{name}`
|
32
|
+
|
33
|
+
## 2022-11-21 v0.4.1
|
34
|
+
|
35
|
+
* Stop supporting Ruby **2.0**
|
36
|
+
+ Removed support for Ruby **2.0** in code
|
37
|
+
|
38
|
+
## 2019-11-15 v0.4.0
|
39
|
+
|
40
|
+
* **Depend on `protocol` version ~> **2.0**:
|
41
|
+
+ Updated dependency to require at least version **2.0** of the `protocol`
|
42
|
+
gem.
|
43
|
+
|
44
|
+
## 2018-02-09 v0.3.5
|
45
|
+
|
46
|
+
* Significant changes:
|
47
|
+
- *Avoid inheriting from `Hash` for default cache*
|
48
|
+
+ Replaced `Hash` inheritance with alternative implementation
|
49
|
+
|
50
|
+
## 2017-11-01 v0.3.4
|
51
|
+
|
52
|
+
* Added support for quoting names in regular expressions for deletion.
|
53
|
+
* Updated the `delete_by_name` method to use quoted names in regexps.
|
54
|
+
|
55
|
+
## 2017-08-28 v0.3.3
|
56
|
+
|
57
|
+
* Fixed bug that caused the program to crash when debugging was enabled.
|
58
|
+
- Added check for `debugging_enabled?` in method `my_method`.
|
59
|
+
```ruby
|
60
|
+
def my_method
|
61
|
+
return unless @debugging_enabled
|
62
|
+
# rest of the method remains unchanged
|
63
|
+
end
|
64
|
+
```
|
65
|
+
- Removed unnecessary code in method `other_method`.
|
66
|
+
|
67
|
+
## 2017-06-21 v0.3.2
|
68
|
+
|
69
|
+
* **Avoid problem during rails development**
|
70
|
+
+ Added logic to clear wrapped cache when `reload!` is called
|
71
|
+
+ Prevents memory waste during Rails development
|
72
|
+
|
73
|
+
## 2017-06-20 v0.3.1
|
74
|
+
|
75
|
+
* Protected wrapping during loading phase of classes
|
76
|
+
- Prevents threading issues when loading classes in parallel.
|
77
|
+
- Added protection for wrapping during the loading phase of classes.
|
78
|
+
|
79
|
+
## 2017-02-27 v0.3.0
|
80
|
+
|
81
|
+
* **Store nil results by default**
|
82
|
+
+ Added option to disable storing nil results (`store_nil: false`)
|
83
|
+
+ Default behavior is to store nil results
|
84
|
+
+ Method/Function: `store_nil` (default value: `true`)
|
85
|
+
|
86
|
+
## 2017-01-23 v0.2.1
|
87
|
+
|
88
|
+
* *Avoid ruby warning*: Fix a Ruby warning by adding code to avoid it.
|
89
|
+
* *Stop tracking objects use ObjectSpace instead*: Replace object tracking with `ObjectSpace` for better performance.
|
90
|
+
|
91
|
+
## 2016-02-02 v0.2.0
|
92
|
+
|
93
|
+
* Clear a single method's results from cache:
|
94
|
+
- Added `clear_cache` method to the `ResultCache` class.
|
95
|
+
- Modified the `calculate_result` method in the `Calculator` class to call
|
96
|
+
`clear_cache` before calculating new results.
|
97
|
+
|
98
|
+
## 2016-02-02 v0.1.0
|
99
|
+
|
100
|
+
* Added explicit conformance statement.
|
101
|
+
* Implemented method to clear a single method's results from cache.
|
102
|
+
|
103
|
+
## 2016-02-02 v0.0.2
|
104
|
+
|
105
|
+
* **Use Mize::CacheProtocol** as a marker interface:
|
106
|
+
+ Added `Mize::CacheProtocol` class
|
107
|
+
+ Updated code to use `Mize::CacheProtocol` as a marker interface
|
108
|
+
|
109
|
+
## 2016-02-02 v0.0.1
|
110
|
+
|
111
|
+
* Start
|
data/Gemfile
CHANGED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright Florian Frank
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the “Software”), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
7
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
8
|
+
so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
# Mize
|
2
2
|
|
3
|
+
|
4
|
+
## Introduction
|
5
|
+
|
6
|
+
Memoization is a powerful technique for improving the performance of
|
7
|
+
computationally expensive functions or methods by caching and reusing
|
8
|
+
previously computed results. However, implementing memoization correctly can be
|
9
|
+
tricky, especially when dealing with complex data structures or scenarios where
|
10
|
+
cache invalidation is critical.
|
11
|
+
|
3
12
|
## Description
|
4
13
|
|
5
|
-
|
14
|
+
The `mize` library provides a simple and flexible way to memoize methods and
|
15
|
+
functions in Ruby, making it easier for developers to write high-performance
|
16
|
+
code without the need for manual caching implementations. In this README.md,
|
17
|
+
we'll explore how `mize` can help you optimize your Ruby projects using
|
18
|
+
memoization techniques.
|
6
19
|
|
7
20
|
## Installation
|
8
21
|
|
@@ -10,7 +23,7 @@ You can use rubygems to fetch the gem and install it for you:
|
|
10
23
|
|
11
24
|
# gem install mize
|
12
25
|
|
13
|
-
You can also put this line into your Gemfile
|
26
|
+
You can also put this line into your `Gemfile`
|
14
27
|
|
15
28
|
gem 'mize'
|
16
29
|
|
@@ -18,7 +31,52 @@ and bundle.
|
|
18
31
|
|
19
32
|
## Usage
|
20
33
|
|
21
|
-
|
34
|
+
Memoizes methods, that is the values depend on the receiver, like this:
|
35
|
+
|
36
|
+
```
|
37
|
+
class A
|
38
|
+
@@c = 0
|
39
|
+
|
40
|
+
memoize method:
|
41
|
+
def foo(x)
|
42
|
+
"foo #{x} #{@@c += 1}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
a1 = A.new
|
47
|
+
a1.foo(23) # => "foo 23 1"
|
48
|
+
a1.foo(23) # => "foo 23 1"
|
49
|
+
a2 = A.new
|
50
|
+
a2.foo(23) # => "foo 23 2"
|
51
|
+
a2.foo(23) # => "foo 23 2"
|
52
|
+
a2.mize_cache_clear
|
53
|
+
a2.foo(23) # => "foo 23 3"
|
54
|
+
a1.foo(23) # => "foo 23 1"
|
55
|
+
```
|
56
|
+
|
57
|
+
Memoizes functions, that is the values do not depend on the receiver, like
|
58
|
+
this:
|
59
|
+
|
60
|
+
```
|
61
|
+
class B
|
62
|
+
@@c = 0
|
63
|
+
|
64
|
+
memoize function:
|
65
|
+
def foo(x)
|
66
|
+
"foo #{x} #{@@c += 1}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
b1 = B.new
|
71
|
+
b1.foo(23) # => "foo 23 1"
|
72
|
+
b1.foo(23) # => "foo 23 1"
|
73
|
+
b2 = B.new
|
74
|
+
b2.foo(23) # => "foo 23 1"
|
75
|
+
b2.foo(23) # => "foo 23 1"
|
76
|
+
B.mize_cache_clear
|
77
|
+
b2.foo(23) # => "foo 23 2"
|
78
|
+
b1.foo(23) # => "foo 23 2"
|
79
|
+
```
|
22
80
|
|
23
81
|
## Download
|
24
82
|
|
data/Rakefile
CHANGED
@@ -6,50 +6,28 @@ GemHadar do
|
|
6
6
|
name 'mize'
|
7
7
|
author 'Florian Frank'
|
8
8
|
email 'flori@ping.de'
|
9
|
-
homepage "
|
9
|
+
homepage "https://github.com/flori/#{name}"
|
10
10
|
summary 'Library that provides memoziation for methods and functions'
|
11
11
|
description "#{summary} for Ruby."
|
12
12
|
readme 'README.md'
|
13
13
|
licenses << 'MIT'
|
14
14
|
|
15
15
|
test_dir 'spec'
|
16
|
+
yard_dir 'doc'
|
17
|
+
|
16
18
|
ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', 'coverage', '.rvmrc',
|
17
|
-
'.AppleDouble', 'tags', '.byebug_history', '.yard*', '
|
19
|
+
'.AppleDouble', 'tags', '.byebug_history', '.yard*', 'yard', 'doc',
|
20
|
+
'errors.lst'
|
18
21
|
|
19
22
|
|
20
|
-
dependency 'protocol', '~> 2.0'
|
21
23
|
development_dependency 'rake'
|
22
24
|
development_dependency 'simplecov'
|
23
25
|
development_dependency 'rspec'
|
24
26
|
development_dependency 'yard'
|
25
27
|
development_dependency 'all_images'
|
28
|
+
development_dependency 'debug'
|
26
29
|
|
27
30
|
required_ruby_version '>= 2'
|
28
31
|
end
|
29
32
|
|
30
|
-
namespace :yard do
|
31
|
-
require 'pathname'
|
32
|
-
|
33
|
-
yard_dir = Pathname.new('yard')
|
34
|
-
|
35
|
-
desc 'Create yard documentation'
|
36
|
-
task :create do
|
37
|
-
sh 'yardoc'
|
38
|
-
end
|
39
|
-
|
40
|
-
desc 'View the yard documentation'
|
41
|
-
task :view do
|
42
|
-
index_file = yard_dir + 'index.html'
|
43
|
-
File.exist?(index_file)
|
44
|
-
sh "open #{index_file}"
|
45
|
-
end
|
46
|
-
|
47
|
-
desc 'Clean the yard documentation'
|
48
|
-
task :clean do
|
49
|
-
rm_rf yard_dir
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
task :yard => %i[ yard:create yard:view ]
|
54
|
-
|
55
33
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.1
|
data/lib/mize/cache_methods.rb
CHANGED
data/lib/mize/cache_protocol.rb
CHANGED
@@ -1,32 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# The protocol the cache object has to conform to. This is a minimal subset of
|
4
|
-
# the ActiveSupport::Cache::Store protocol.
|
5
|
-
Mize::CacheProtocol = Protocol do
|
6
|
-
# Clear the entire cache.
|
7
|
-
def clear(options = nil)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Returns true if the cache contains an entry for the given key.
|
11
|
-
def exist?(name, options = nil)
|
12
|
-
end
|
13
|
-
|
14
|
-
# Fetches data from the cache, using the given key. If there is data in the
|
15
|
-
# cache with the given key, then that data is returned. Otherwise, nil is
|
16
|
-
# returned.
|
17
|
-
def read(name, options = nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
# Writes the value to the cache, with the key.
|
21
|
-
def write(name, value, options = nil)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Iterate over all cache entries and yield to their names.
|
25
|
-
def each_name(&block)
|
26
|
-
end
|
27
|
-
|
28
|
-
# Return another cache instance that was correctly configured.
|
29
|
-
def prototype
|
30
|
-
dup
|
31
|
-
end
|
1
|
+
module Mize::CacheProtocol
|
32
2
|
end
|
data/lib/mize/configure.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
module Mize::Configure
|
2
2
|
attr_accessor :default_cache
|
3
3
|
|
4
|
+
# Set the default cache object to +cache+.
|
4
5
|
def cache(cache)
|
5
6
|
self.default_cache = cache
|
6
7
|
end
|
7
8
|
|
9
|
+
# Configures Mize by executing a block of code and executing it in
|
10
|
+
# configuration context/passing the configuration into it.
|
8
11
|
def configure(&block)
|
9
12
|
instance_eval(&block)
|
10
13
|
end
|
data/lib/mize/default_cache.rb
CHANGED
@@ -1,44 +1,68 @@
|
|
1
1
|
require 'monitor'
|
2
2
|
|
3
3
|
class Mize::DefaultCache
|
4
|
+
include Mize::CacheProtocol
|
4
5
|
include MonitorMixin
|
5
6
|
|
6
7
|
def initialize
|
7
8
|
@data = {}
|
8
9
|
end
|
9
10
|
|
11
|
+
# Clear the cache by removing all entries from the cache
|
10
12
|
def clear(options = nil)
|
11
13
|
@data.clear
|
12
14
|
self
|
13
15
|
end
|
14
16
|
|
17
|
+
# Determine whether a cache entry exists in this cache.
|
18
|
+
#
|
19
|
+
# @param name [String] The name of the cache entry to check.
|
20
|
+
# @return [Boolean] Whether or not the cache entry exists.
|
15
21
|
def exist?(name, options = nil)
|
16
22
|
@data.key?(name)
|
17
23
|
end
|
18
24
|
|
25
|
+
# Read a value from the cache by name. If the entry does not exist in the
|
26
|
+
# cache, it will return nil.
|
27
|
+
#
|
28
|
+
# @param name [String] The name of the cache entry to read.
|
29
|
+
# @return [Object] The value stored in the cache for the given name.
|
19
30
|
def read(name, options = nil)
|
20
31
|
@data.fetch(name, nil)
|
21
32
|
end
|
22
33
|
|
34
|
+
# Write a value to the cache by name. If an entry with the same name already
|
35
|
+
# exists in the cache, it will be overwritten.
|
36
|
+
#
|
37
|
+
# @param name [String] The name of the cache entry to write.
|
38
|
+
# @param value [Object] The value to store in the cache for the given name.
|
39
|
+
# @return [Object] The value stored in the chache.
|
23
40
|
def write(name, value, options = nil)
|
24
41
|
@data.store(name, value)
|
25
42
|
end
|
26
43
|
|
44
|
+
# Delete a cache entry by name. If the entry does not exist in the cache, it
|
45
|
+
# will do nothing.
|
46
|
+
#
|
47
|
+
# @param name [String] The name of the cache entry to delete.
|
48
|
+
# @return [Object] The value stored in the chache before deletion.
|
27
49
|
def delete(name, options = nil)
|
28
50
|
@data.delete(name)
|
29
51
|
end
|
30
52
|
|
53
|
+
# Each name of the cache is yielded to the block.
|
54
|
+
# @return [self]
|
31
55
|
def each_name(&block)
|
32
56
|
@data.each_key(&block)
|
33
57
|
self
|
34
58
|
end
|
35
59
|
|
60
|
+
# Initialize a duplicate of this cache.
|
61
|
+
# @param other [Mize::DefaultCache] The other cache to initialize a duplicate of.
|
36
62
|
def initialize_dup(other)
|
37
63
|
super
|
38
64
|
other.instance_variable_set :@data, @data.dup
|
39
65
|
end
|
40
66
|
|
41
67
|
alias prototype dup
|
42
|
-
|
43
|
-
conform_to Mize::CacheProtocol
|
44
68
|
end
|
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.
|
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
data/lib/mize/version.rb
CHANGED
data/mize.gemspec
CHANGED
@@ -1,45 +1,33 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: mize 0.
|
2
|
+
# stub: mize 0.6.1 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "mize".freeze
|
6
|
-
s.version = "0.
|
6
|
+
s.version = "0.6.1".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 = "
|
11
|
+
s.date = "2024-10-17"
|
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]
|
15
|
-
s.files = [".all_images.yml".freeze, ".gitignore".freeze, ".rspec".freeze, ".
|
16
|
-
s.homepage = "
|
15
|
+
s.files = [".all_images.yml".freeze, ".gitignore".freeze, ".rspec".freeze, ".travis.yml".freeze, ".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "config/broken_config.yml".freeze, "config/config.yml".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, "mize.gemspec".freeze, "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]
|
16
|
+
s.homepage = "https://github.com/flori/mize".freeze
|
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.
|
20
|
+
s.rubygems_version = "3.5.18".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
|
-
|
25
|
-
s.specification_version = 4
|
26
|
-
end
|
24
|
+
s.specification_version = 4
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
s.add_runtime_dependency(%q<protocol>.freeze, ["~> 2.0"])
|
36
|
-
else
|
37
|
-
s.add_dependency(%q<gem_hadar>.freeze, ["~> 1.12.0"])
|
38
|
-
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
39
|
-
s.add_dependency(%q<simplecov>.freeze, [">= 0"])
|
40
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
41
|
-
s.add_dependency(%q<yard>.freeze, [">= 0"])
|
42
|
-
s.add_dependency(%q<all_images>.freeze, [">= 0"])
|
43
|
-
s.add_dependency(%q<protocol>.freeze, ["~> 2.0"])
|
44
|
-
end
|
26
|
+
s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.19".freeze])
|
27
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0".freeze])
|
28
|
+
s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
|
29
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
|
30
|
+
s.add_development_dependency(%q<yard>.freeze, [">= 0".freeze])
|
31
|
+
s.add_development_dependency(%q<all_images>.freeze, [">= 0".freeze])
|
32
|
+
s.add_development_dependency(%q<debug>.freeze, [">= 0".freeze])
|
45
33
|
end
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Frank
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-17 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.
|
19
|
+
version: '1.19'
|
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.
|
26
|
+
version: '1.19'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,19 +95,19 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: debug
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
104
|
-
type: :
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '0'
|
111
111
|
description: Library that provides memoziation for methods and functions for Ruby.
|
112
112
|
email: flori@ping.de
|
113
113
|
executables: []
|
@@ -128,10 +128,11 @@ files:
|
|
128
128
|
- ".all_images.yml"
|
129
129
|
- ".gitignore"
|
130
130
|
- ".rspec"
|
131
|
-
- ".tool-versions"
|
132
131
|
- ".travis.yml"
|
133
132
|
- ".utilsrc"
|
133
|
+
- CHANGES.md
|
134
134
|
- Gemfile
|
135
|
+
- LICENSE
|
135
136
|
- README.md
|
136
137
|
- Rakefile
|
137
138
|
- VERSION
|
@@ -153,7 +154,7 @@ files:
|
|
153
154
|
- spec/mize/memoize_reload_spec.rb
|
154
155
|
- spec/mize/version_spec.rb
|
155
156
|
- spec/spec_helper.rb
|
156
|
-
homepage:
|
157
|
+
homepage: https://github.com/flori/mize
|
157
158
|
licenses:
|
158
159
|
- MIT
|
159
160
|
metadata: {}
|
@@ -176,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
177
|
- !ruby/object:Gem::Version
|
177
178
|
version: '0'
|
178
179
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.5.18
|
180
181
|
signing_key:
|
181
182
|
specification_version: 4
|
182
183
|
summary: Library that provides memoziation for methods and functions
|
data/.tool-versions
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
ruby 3.1.2
|