adornable 1.1.1 → 1.2.0
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 +4 -4
- data/README.md +1 -0
- data/adornable.gemspec +1 -1
- data/lib/adornable/decorators.rb +7 -4
- data/lib/adornable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc81717998b4dc097647c96e4b7c89664b2d0c6969100dd22d713ba9c1720619
|
4
|
+
data.tar.gz: a3998df4caeb6db3823a218fc77ac3d1d56949e3f9a66cc340f65465d9037686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4aaf8fe2928bb4652dc5a7b1f235fadc7114580cfc29d91a9fdf508edbba15cccc09627b6a097552774c73babede934ca77a9388fa7ce1bfdbfb5975ab0661da
|
7
|
+
data.tar.gz: cc2ec1780014bfb5043a44857a2d9fc6eb7957ec245fef03accbe64436c11cc9f2596105d25d5e888b136ca27d57565ec414f9fbb466f72fc425744d6fe69af2
|
data/README.md
CHANGED
@@ -156,6 +156,7 @@ end
|
|
156
156
|
- `decorate :log` logs the method name and any passed arguments to the console
|
157
157
|
- `decorate :memoize` caches the result of the first call and returns that initial result (and does not execute the method again) for any additional calls. By default, it namespaces the cache by the arguments passed to the method, so it will re-compute only if the arguments change; if the arguments are the same as any previous time the method was called, it will return the cached result instead.
|
158
158
|
- pass the `for_any_arguments: true` option (e.g., `decorate :memoize, for_any_arguments: true`) to ignore the arguments in the caching process and simply memoize the result no matter what
|
159
|
+
- a `nil` value returned from a memoized method will still be cached like any other value
|
159
160
|
|
160
161
|
> **Note:** in the case of multiple decorators decorating a method, each is executed from top to bottom.
|
161
162
|
|
data/adornable.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.email = ["kjleitz@gmail.com"]
|
12
12
|
|
13
13
|
spec.summary = "Method decorators for Ruby"
|
14
|
-
spec.description = "Adornable provides the ability to cleanly decorate methods in Ruby. You can make and use your own decorators, and you can also use some of the built-in ones that the gem provides. _Decorating_ methods is as simple as slapping a `decorate :some_decorator` above your method definition. _Defining_ decorators can be as simple as defining a method that yields to a block, or as complex as manipulating the decorated method's receiver and arguments, and/or changing the functionality of the decorator based on custom options supplied to it when initially applying the decorator."
|
14
|
+
spec.description = "Adornable provides the ability to cleanly decorate methods in Ruby. You can make and use your own decorators, and you can also use some of the built-in ones that the gem provides. _Decorating_ methods is as simple as slapping a `decorate :some_decorator` above your method definition. _Defining_ decorators can be as simple as defining a method that yields to a block, or as complex as manipulating the decorated method's receiver and arguments, and/or changing the functionality of the decorator based on custom options supplied to it when initially applying the decorator." # rubocop:disable Layout/LineLength
|
15
15
|
spec.homepage = "https://github.com/kjleitz/adornable"
|
16
16
|
spec.license = "MIT"
|
17
17
|
spec.required_ruby_version = ">= 2.4.7"
|
data/lib/adornable/decorators.rb
CHANGED
@@ -24,9 +24,12 @@ module Adornable
|
|
24
24
|
method_receiver = context.method_receiver
|
25
25
|
method_name = context.method_name
|
26
26
|
memo_var_name = :"@adornable_memoized_#{method_receiver.object_id}_#{method_name}"
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
if instance_variable_defined?(memo_var_name)
|
29
|
+
instance_variable_get(memo_var_name)
|
30
|
+
else
|
31
|
+
instance_variable_set(memo_var_name, yield)
|
32
|
+
end
|
30
33
|
end
|
31
34
|
|
32
35
|
def self.memoize_for_arguments(context)
|
@@ -37,7 +40,7 @@ module Adornable
|
|
37
40
|
memo = instance_variable_get(memo_var_name) || {}
|
38
41
|
instance_variable_set(memo_var_name, memo)
|
39
42
|
args_key = method_args.inspect
|
40
|
-
memo[args_key] = yield
|
43
|
+
memo[args_key] = yield unless memo.key?(args_key)
|
41
44
|
memo[args_key]
|
42
45
|
end
|
43
46
|
end
|
data/lib/adornable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adornable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keegan Leitz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -172,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
172
172
|
- !ruby/object:Gem::Version
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
|
-
rubygems_version: 3.
|
175
|
+
rubygems_version: 3.0.9
|
176
176
|
signing_key:
|
177
177
|
specification_version: 4
|
178
178
|
summary: Method decorators for Ruby
|