around_the_world 0.19.2 → 0.19.3

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: 2c44e4600e2952abeee8b3742fda6da57a9d35386029cccdf4b74209785dffea
4
- data.tar.gz: d9d00428029805db8a253c75c37265fa5342cbdd884a861f2c80baa56920ce61
3
+ metadata.gz: ad6bd225025bb0be327d8f7718ca5ae173fc2ad8364cac0859ff6f8c7edc0c67
4
+ data.tar.gz: 35c0eb58c034f9579a195a297652efd2eb1128d9f33470d082e9ac212062ccb1
5
5
  SHA512:
6
- metadata.gz: c1f2264e9c186c8a7dce5a4c93a61d27efe8097fd319910ed61134aa4e21b5aa5c4520b3be976fc5d08d3b3b01160a48b47075068daf27f85ab24570e67dda5c
7
- data.tar.gz: c3985023bd19fc5ed402f367acc15d23d619958454f27ac924bf8f138acbee56eb24c01e0536e4fbf409d22558ab963f230d71d2b0a6f2cc52765f676457a66c
6
+ metadata.gz: a0546264a8e3b6af2534532d1f1efe1d7100b8364c127e26805af78ab8261e9713ebac7f72f74ad29b7dabf21fcc98f2faab40f9440fcf7ba28e09a04c25b343
7
+ data.tar.gz: b1dcc397ed9da4a981c612c89e68477832ecee8fb065baaca2d2ad73c1596b02edac2e67a0d19741378563eea2002b710ae97bff405341ae495727286e681185
data/README.md CHANGED
@@ -22,16 +22,95 @@ gem "around_the_world"
22
22
  ```
23
23
 
24
24
  And then execute:
25
-
26
- $ bundle
25
+ ```bash
26
+ $ bundle
27
+ ```
27
28
 
28
29
  Or install it yourself as:
29
30
 
30
- $ gem install around_the_world
31
+ ```bash
32
+ $ gem install around_the_world
33
+ ```
31
34
 
32
35
  ## Usage
33
36
 
34
- TODO: Write usage instructions here
37
+ Define a method that gets called _around_ the given instance method:
38
+
39
+ ```ruby
40
+ class SomeClass
41
+ include AroundTheWorld
42
+
43
+ def did_something_happened?
44
+ true
45
+ end
46
+
47
+ around_method :did_something_happened? do |*args|
48
+ things_happened = super(*args)
49
+
50
+ if things_happened
51
+ "Something happened!"
52
+ else
53
+ "Nothing to see here..."
54
+ end
55
+ end
56
+ end
57
+ ```
58
+
59
+ ```
60
+ > SomeClass.new.did_something_happened?
61
+ => "Something happened!"
62
+ ```
63
+
64
+ `around_method` accepts an option hash `prevent_double_wrapping_for: [Object]`. If defined, this prevents wrapping the method twice for a given purpose. It accepts any value:
65
+
66
+
67
+ ```ruby
68
+ class SomeClass
69
+ include AroundTheWorld
70
+
71
+ def some_method
72
+ "method behavior"
73
+ end
74
+
75
+ around_method :some_method, prevent_double_wrapping_for: :memoization do |*args|
76
+ @memoized ||= super(*args)
77
+ end
78
+
79
+ around_method :some_method, prevent_double_wrapping_for: :memoization do |*args|
80
+ @memoized ||= super(*args)
81
+ end
82
+ end
83
+ ```
84
+
85
+ Results in:
86
+
87
+ ```
88
+ # => AroundTheWorld::DoubleWrapError:
89
+ "Module AroundTheWorld:ProxyModule:memoization already defines the method :some_method"
90
+ ```
91
+
92
+ It works for class methods too:
93
+
94
+ ```ruby
95
+ class SomeClass
96
+ class << self
97
+ include AroundTheWorld
98
+
99
+ def a_singleton_method; end
100
+
101
+ around_method :a_singleton_method do |*args|
102
+ super(*args)
103
+
104
+ "It works for class methods too!"
105
+ end
106
+ end
107
+ end
108
+ ```
109
+
110
+ ```
111
+ > SomeClass.a_singleton_method
112
+ => "It works for class methods too!"
113
+ ```
35
114
 
36
115
  ## Development
37
116
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module AroundTheWorld
4
4
  # This constant is managed by spicerack
5
- VERSION = "0.19.2"
5
+ VERSION = "0.19.3"
6
6
  end
@@ -5,6 +5,7 @@ require_relative "around_the_world/method_wrapper"
5
5
  require_relative "around_the_world/proxy_module"
6
6
  require_relative "around_the_world/version"
7
7
  require "active_support/concern"
8
+ require "active_support/core_ext/object/blank"
8
9
  require "active_support/descendants_tracker"
9
10
 
10
11
  module AroundTheWorld
@@ -21,8 +22,8 @@ module AroundTheWorld
21
22
  #
22
23
  # @example
23
24
  # class SomeClass
24
- # around_method :dont_look_in_here do
25
- # things_happened = super
25
+ # around_method :dont_look_in_here do |*args|
26
+ # things_happened = super(*args)
26
27
  #
27
28
  # if things_happened
28
29
  # "Something happened!"
@@ -40,19 +41,19 @@ module AroundTheWorld
40
41
  # => "Something happened!"
41
42
  #
42
43
  # @example
43
- # around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do
44
- # @memoized ||= super
44
+ # around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do |*args|
45
+ # @memoized ||= super(*args)
45
46
  # end
46
47
  #
47
- # around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do
48
- # @memoized ||= super
48
+ # around_method :dont_look_in_here, prevent_double_wrapping_for: :memoization do |*args|
49
+ # @memoized ||= super(*args)
49
50
  # end
50
51
  # # => AroundTheWorld::DoubleWrapError:
51
52
  # "Module AroundTheWorld:ProxyModule:memoization already defines the method :dont_look_in_here"
52
53
  #
53
- # around_method :dont_look_in_here do
54
+ # around_method :dont_look_in_here do |*args|
54
55
  # do_something_else
55
- # super
56
+ # super(*args)
56
57
  # end
57
58
  # # => no error raised
58
59
  #
@@ -63,8 +64,8 @@ module AroundTheWorld
63
64
  # class << self
64
65
  # def a_singleton_method; end
65
66
  #
66
- # around_method :a_singleton_method do
67
- # super
67
+ # around_method :a_singleton_method do |*args|
68
+ # super(*args)
68
69
  # "It works for class methods too!"
69
70
  # end
70
71
  # end
@@ -73,6 +74,7 @@ module AroundTheWorld
73
74
  # SomeClass.a_singleton_method
74
75
  # => "It works for class methods too!"
75
76
  #
77
+ # @api public
76
78
  # @param method_name [Symbol]
77
79
  # @param :prevent_double_wrapping_for [Object]
78
80
  # If defined, this prevents wrapping the method twice for a given purpose. Accepts any argument.
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.19.2
4
+ version: 0.19.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Rettberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-02 00:00:00.000000000 Z
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  requirements: []
64
- rubygems_version: 3.0.3
64
+ rubygems_version: 3.0.6
65
65
  signing_key:
66
66
  specification_version: 4
67
67
  summary: Allows you to easily wrap methods with custom logic on any class