dry-core 0.4.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/dry/core/memoizable.rb +68 -0
- data/lib/dry/core/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b4f56e04c1cdf9503a86498dafcd37a2e46d1c18d5a40e9974795cd656d183e
|
4
|
+
data.tar.gz: a774b50a5616c40a6bac42240ae0e666b10d847bf083922bfd93921828f658e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab32eee7ff76b9176cd1fc80f0112c67918557d655dd24f043b65256c86fed3ab7469cb642ef31a75aa5a8e6c6abc9abc709f3591cac7b6daef9fee0def6454f
|
7
|
+
data.tar.gz: 0a24c3dd493063e9046740e52d9a4e54e8e2df874577830c1c066dfcf27bfcb7a824a4d2da1ef55849e23806a0d7e3bfe37ca4ca796be3890dbff19ff0b4fd14
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
|
+
# v0.4.5 2018-03-14
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
* `Dry::Core::Memoizable`, which provides a `memoize` macro for memoizing results of instance methods (timriley)
|
6
|
+
|
7
|
+
[Compare v0.4.5...v0.4.5](https://github.com/dry-rb/dry-core/compare/v0.4.4...v0.4.5)
|
8
|
+
|
1
9
|
# v0.4.4 2018-02-10
|
2
10
|
|
3
11
|
### Added
|
4
12
|
|
5
13
|
* `deprecate_constant` overrides `Module#deprecate_constant` and issues a labeled message on accessing a deprecated constant (flash-gordon)
|
6
|
-
* `Undefined.default` which accepts two arguments and returns the first if it's not `
|
14
|
+
* `Undefined.default` which accepts two arguments and returns the first if it's not `Undefined`; otherwise, returns the second one or yields a block (flash-gordon)
|
7
15
|
|
8
16
|
[Compare v0.4.3...v0.4.4](https://github.com/dry-rb/dry-core/compare/v0.4.3...v0.4.4)
|
9
17
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Dry
|
2
|
+
module Core
|
3
|
+
module Memoizable
|
4
|
+
MEMOIZED_HASH = {}.freeze
|
5
|
+
|
6
|
+
module ClassInterface
|
7
|
+
def memoize(*names)
|
8
|
+
prepend(Memoizer.new(self, names))
|
9
|
+
end
|
10
|
+
|
11
|
+
def new(*)
|
12
|
+
obj = super
|
13
|
+
obj.instance_variable_set(:'@__memoized__', MEMOIZED_HASH.dup)
|
14
|
+
obj
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(klass)
|
19
|
+
super
|
20
|
+
klass.extend(ClassInterface)
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :__memoized__
|
24
|
+
|
25
|
+
# @api private
|
26
|
+
class Memoizer < Module
|
27
|
+
attr_reader :klass
|
28
|
+
attr_reader :names
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
def initialize(klass, names)
|
32
|
+
@names = names
|
33
|
+
@klass = klass
|
34
|
+
define_memoizable_names!
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @api private
|
40
|
+
def define_memoizable_names!
|
41
|
+
names.each do |name|
|
42
|
+
meth = klass.instance_method(name)
|
43
|
+
|
44
|
+
if meth.parameters.size > 0
|
45
|
+
define_method(name) do |*args|
|
46
|
+
name_with_args = :"#{name}_#{args.hash}"
|
47
|
+
|
48
|
+
if __memoized__.key?(name_with_args)
|
49
|
+
__memoized__[name_with_args]
|
50
|
+
else
|
51
|
+
__memoized__[name_with_args] = super(*args)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
else
|
55
|
+
define_method(name) do
|
56
|
+
if __memoized__.key?(name)
|
57
|
+
__memoized__[name]
|
58
|
+
else
|
59
|
+
__memoized__[name] = super()
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/lib/dry/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/dry/core/errors.rb
|
97
97
|
- lib/dry/core/extensions.rb
|
98
98
|
- lib/dry/core/inflector.rb
|
99
|
+
- lib/dry/core/memoizable.rb
|
99
100
|
- lib/dry/core/version.rb
|
100
101
|
homepage: https://github.com/dry-rb/dry-core
|
101
102
|
licenses:
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
119
|
version: '0'
|
119
120
|
requirements: []
|
120
121
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.7.
|
122
|
+
rubygems_version: 2.7.5
|
122
123
|
signing_key:
|
123
124
|
specification_version: 4
|
124
125
|
summary: A toolset of small support modules used throughout the dry-rb ecosystem.
|