around_the_world 0.23.3 → 0.23.8
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 +24 -10
- data/lib/around_the_world.rb +26 -20
- data/lib/around_the_world/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23a890fe677d896aa33ac95d8566e8471077ea8da13b1e1cfd1f31f86ba6b6c7
|
4
|
+
data.tar.gz: a5b921005580bfad7decdb3473494e13f39db5fc1a47311caa230a69d1a19bbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7bef9bce830d89210ac4634ff63697357c83a7707443b0e29f128046bfecbab567785c0d6dadc990b91df077dda90972ac6beb6874f5cdea324b8ee97f14f66
|
7
|
+
data.tar.gz: 00ad4983a51f3e5f987c10baeea406acd4936d6ba5bb34e2f980792a8a5fe47a418b4f0c40dbbfa91fdfa29343cda4423acc937c111968a8e796b612785f2d4a
|
data/README.md
CHANGED
@@ -40,12 +40,20 @@ Define a method that gets called _around_ the given instance method:
|
|
40
40
|
class SomeClass
|
41
41
|
include AroundTheWorld
|
42
42
|
|
43
|
+
def make_something_happen!
|
44
|
+
@something_happened = true
|
45
|
+
end
|
46
|
+
|
43
47
|
def did_something_happened?
|
44
|
-
|
48
|
+
!!@something_happened
|
45
49
|
end
|
46
|
-
|
47
|
-
around_method :did_something_happened? do |*args
|
48
|
-
|
50
|
+
|
51
|
+
around_method :make_something_happen!, :did_something_happened? do |*args| # use |...| for ruby 2.7+
|
52
|
+
# For Ruby <= 2.6:
|
53
|
+
things_happened = super(*args)
|
54
|
+
|
55
|
+
#Or, for Ruby <= 2.7:
|
56
|
+
things_happened = super(...)
|
49
57
|
|
50
58
|
if things_happened
|
51
59
|
"Something happened!"
|
@@ -57,6 +65,12 @@ end
|
|
57
65
|
```
|
58
66
|
|
59
67
|
```
|
68
|
+
> SomeClass.new.did_something_happened?
|
69
|
+
=> "Nothing to see here..."
|
70
|
+
|
71
|
+
> SomeClass.new.make_something_happen!
|
72
|
+
=> "Something happened!"
|
73
|
+
|
60
74
|
> SomeClass.new.did_something_happened?
|
61
75
|
=> "Something happened!"
|
62
76
|
```
|
@@ -72,12 +86,12 @@ class SomeClass
|
|
72
86
|
"method behavior"
|
73
87
|
end
|
74
88
|
|
75
|
-
around_method :some_method, prevent_double_wrapping_for: :memoization do
|
76
|
-
@memoized ||= super(
|
89
|
+
around_method :some_method, prevent_double_wrapping_for: :memoization do |...|
|
90
|
+
@memoized ||= super(...)
|
77
91
|
end
|
78
92
|
|
79
|
-
around_method :some_method, prevent_double_wrapping_for: :memoization do
|
80
|
-
@memoized ||= super(
|
93
|
+
around_method :some_method, prevent_double_wrapping_for: :memoization do |...|
|
94
|
+
@memoized ||= super(...)
|
81
95
|
end
|
82
96
|
end
|
83
97
|
```
|
@@ -98,8 +112,8 @@ class SomeClass
|
|
98
112
|
|
99
113
|
def a_singleton_method; end
|
100
114
|
|
101
|
-
around_method :a_singleton_method do
|
102
|
-
super(
|
115
|
+
around_method :a_singleton_method do |...|
|
116
|
+
super(...) # See above for ruby <= 2.6 syntax
|
103
117
|
|
104
118
|
"It works for class methods too!"
|
105
119
|
end
|
data/lib/around_the_world.rb
CHANGED
@@ -23,9 +23,13 @@ module AroundTheWorld
|
|
23
23
|
#
|
24
24
|
# @example
|
25
25
|
# class SomeClass
|
26
|
-
# around_method :
|
27
|
-
#
|
28
|
-
#
|
26
|
+
# around_method :make_something_happen!, :did_something_happened? do |*args| # use |...| for ruby 2.7+
|
27
|
+
# # For Ruby <= 2.6:
|
28
|
+
# things_happened = super(*args)
|
29
|
+
|
30
|
+
# #Or, for Ruby <= 2.7:
|
31
|
+
# things_happened = super(...)
|
32
|
+
|
29
33
|
# if things_happened
|
30
34
|
# "Something happened!"
|
31
35
|
# else
|
@@ -42,19 +46,19 @@ module AroundTheWorld
|
|
42
46
|
# => "Something happened!"
|
43
47
|
#
|
44
48
|
# @example
|
45
|
-
# around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do
|
46
|
-
# @memoized ||= super(
|
49
|
+
# around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do |...|
|
50
|
+
# @memoized ||= super(...)
|
47
51
|
# end
|
48
52
|
#
|
49
|
-
# around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do
|
50
|
-
# @memoized ||= super(
|
53
|
+
# around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do |...|
|
54
|
+
# @memoized ||= super(...)
|
51
55
|
# end
|
52
56
|
# # => AroundTheWorld::DoubleWrapError:
|
53
57
|
# "Module AroundTheWorld:ProxyModule:memoization already defines the method :dont_look_in_here"
|
54
58
|
#
|
55
|
-
# around_method :dont_look_in_here do
|
59
|
+
# around_method :dont_look_in_here do |...|
|
56
60
|
# do_something_else
|
57
|
-
# super(
|
61
|
+
# super(...)
|
58
62
|
# end
|
59
63
|
# # => no error raised
|
60
64
|
#
|
@@ -65,8 +69,8 @@ module AroundTheWorld
|
|
65
69
|
# class << self
|
66
70
|
# def a_singleton_method; end
|
67
71
|
#
|
68
|
-
# around_method :a_singleton_method do
|
69
|
-
# super(
|
72
|
+
# around_method :a_singleton_method do |...|
|
73
|
+
# super(...)
|
70
74
|
# "It works for class methods too!"
|
71
75
|
# end
|
72
76
|
# end
|
@@ -76,19 +80,21 @@ module AroundTheWorld
|
|
76
80
|
# => "It works for class methods too!"
|
77
81
|
#
|
78
82
|
# @api public
|
79
|
-
# @param
|
83
|
+
# @param method_names [Array<Symbol, String>] A list of methods to be wrapped
|
80
84
|
# @param :prevent_double_wrapping_for [Object]
|
81
85
|
# If defined, this prevents wrapping the method twice for a given purpose. Accepts any argument.
|
82
86
|
# @param :allow_undefined_method [Boolean] When false, an error is raised if the wrapped method is not
|
83
87
|
# explicitly defined by the target module or class. Default: false
|
84
|
-
def around_method(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
88
|
+
def around_method(*method_names, prevent_double_wrapping_for: nil, allow_undefined_method: false, &block)
|
89
|
+
method_names.each do |method_name|
|
90
|
+
MethodWrapper.wrap(
|
91
|
+
method_name: method_name,
|
92
|
+
target: self,
|
93
|
+
prevent_double_wrapping_for: prevent_double_wrapping_for,
|
94
|
+
allow_undefined_method: allow_undefined_method,
|
95
|
+
&block
|
96
|
+
)
|
97
|
+
end
|
92
98
|
end
|
93
99
|
end
|
94
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: around_the_world
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.23.
|
4
|
+
version: 0.23.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Allen Rettberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -47,7 +47,7 @@ metadata:
|
|
47
47
|
homepage_uri: https://github.com/Freshly/spicerack/tree/master/around_the_world
|
48
48
|
source_code_uri: https://github.com/Freshly/spicerack/tree/master/around_the_world
|
49
49
|
changelog_uri: https://github.com/Freshly/spicerack/blob/master/around_the_world/CHANGELOG.md
|
50
|
-
documentation_uri: https://www.rubydoc.info/gems/around_the_world/0.23.
|
50
|
+
documentation_uri: https://www.rubydoc.info/gems/around_the_world/0.23.8
|
51
51
|
post_install_message:
|
52
52
|
rdoc_options: []
|
53
53
|
require_paths:
|
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
63
|
- !ruby/object:Gem::Version
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
66
|
+
rubygems_version: 3.1.2
|
67
67
|
signing_key:
|
68
68
|
specification_version: 4
|
69
69
|
summary: Allows you to easily wrap methods with custom logic on any class
|