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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fafff3aedd6efd98d5114af5c4910af0aca7252bea80091382dab3fe7c7bd5fb
4
- data.tar.gz: 6038aa1b445beebd7a066397838f7600999be195c34e8580869f5810eaeb6204
3
+ metadata.gz: 23a890fe677d896aa33ac95d8566e8471077ea8da13b1e1cfd1f31f86ba6b6c7
4
+ data.tar.gz: a5b921005580bfad7decdb3473494e13f39db5fc1a47311caa230a69d1a19bbf
5
5
  SHA512:
6
- metadata.gz: 586d9126b97c271775160d21d21bbb6384e63e33eca890bf8ccc83b2547edd25db4281832e2543bdb5610f6707e716d909d58826e84a60fcf2470b3da462f57d
7
- data.tar.gz: f4e9d6ff94769138dcf6b4b0c8424472bc094171c8d2a4d65b5cbc44ecfd5f7d6581751808ff9f491953643244bfc0430e5235595035df6795f23f4ce5398d24
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
- true
48
+ !!@something_happened
45
49
  end
46
-
47
- around_method :did_something_happened? do |*args, **opts|
48
- things_happened = super(*args, **opts)
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 |*args, **opts|
76
- @memoized ||= super(*args, **opts)
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 |*args, **opts|
80
- @memoized ||= super(*args, **opts)
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 |*args, **opts|
102
- super(*args, **opts)
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
@@ -23,9 +23,13 @@ module AroundTheWorld
23
23
  #
24
24
  # @example
25
25
  # class SomeClass
26
- # around_method :dont_look_in_here do |*args, **opts|
27
- # things_happened = super(*args, **opts)
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 |*args, **opts|
46
- # @memoized ||= super(*args, **opts)
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 |*args, **opts|
50
- # @memoized ||= super(*args, **opts)
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 |*args, **opts|
59
+ # around_method :dont_look_in_here do |...|
56
60
  # do_something_else
57
- # super(*args, **opts)
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 |*args, **opts|
69
- # super(*args, **opts)
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 method_name [Symbol]
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(method_name, prevent_double_wrapping_for: nil, allow_undefined_method: false, &block)
85
- MethodWrapper.wrap(
86
- method_name: method_name,
87
- target: self,
88
- prevent_double_wrapping_for: prevent_double_wrapping_for,
89
- allow_undefined_method: allow_undefined_method,
90
- &block
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AroundTheWorld
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.23.3"
5
+ VERSION = "0.23.8"
6
6
  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.3
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-03-27 00:00:00.000000000 Z
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.3
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.0.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