duck_puncher 4.2.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -7
- data/lib/duck_puncher/defaults.rb +1 -2
- data/lib/duck_puncher/registration.rb +5 -0
- data/lib/duck_puncher/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d87f6e9cc70035a1882583f6f8118b50a48a727
|
4
|
+
data.tar.gz: ef1253af39b88d4ca68738aa5ae278c19f2cc235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30e60aeae2f9484ece1756527f2b5217a5af1fecee7fbe72435d7c368d022d72bf47795011ef3a6de8a6698ee280492bba9f408d9eea6b576224bd7323b66470
|
7
|
+
data.tar.gz: 0fe659cc0d20d179246eedd5522da3ea2fa824489b40ca2785ef56b1fd20037af3a75a6649d5946ae4447450dfd3f1d58e617ef15b0929d4ae66ba67e9d3b159
|
data/README.md
CHANGED
@@ -66,20 +66,20 @@ DuckPuncher.(Object, only: :punch)
|
|
66
66
|
`DuckPuncher` extends the amazing [Usable](https://github.com/ridiculous/usable) gem, so you can configure only the punches you want! For instance:
|
67
67
|
|
68
68
|
```ruby
|
69
|
-
DuckPuncher.
|
69
|
+
DuckPuncher.(Numeric, only: [:to_currency, :to_duration])
|
70
70
|
```
|
71
71
|
|
72
72
|
If you punch `Object` then you can use `#punch!` on any object to extend individual instances:
|
73
73
|
|
74
74
|
```ruby
|
75
|
-
>> DuckPuncher.
|
75
|
+
>> DuckPuncher.(Object, only: :punch!)
|
76
76
|
>> %w[yes no 1].punch!.m!(:punch).m(:to_boolean)
|
77
77
|
=> [true, false, true]
|
78
78
|
```
|
79
79
|
|
80
80
|
Alternatively, there is also the `Object#punch` method which returns a decorated copy of an object with punches mixed in:
|
81
81
|
```ruby
|
82
|
-
>> DuckPuncher.
|
82
|
+
>> DuckPuncher.(Object, only: :punch)
|
83
83
|
>> %w[1 2 3].punch.m(:to_i)
|
84
84
|
=> [1, 2, 3]
|
85
85
|
```
|
@@ -106,7 +106,7 @@ def soft_punch
|
|
106
106
|
end
|
107
107
|
|
108
108
|
def hard_punch
|
109
|
-
('a'..'z').
|
109
|
+
('a'..'z').punch!.m!(:upcase).mm!(:*, 3).echo
|
110
110
|
end
|
111
111
|
|
112
112
|
>> soft_punch
|
@@ -152,13 +152,15 @@ end
|
|
152
152
|
DuckPuncher.register User, :Billable, :Retryable
|
153
153
|
|
154
154
|
# Add the #punch method to User instances
|
155
|
-
DuckPuncher.
|
155
|
+
DuckPuncher.(Object, only: :punch)
|
156
156
|
|
157
157
|
# Usage
|
158
158
|
user = User.new('Ryan').punch
|
159
159
|
user.call_with_retry(19.99)
|
160
160
|
```
|
161
161
|
|
162
|
+
To register _and_ punch in one swoop, use `DuckPuncher.register!`
|
163
|
+
|
162
164
|
## Install
|
163
165
|
|
164
166
|
```ruby
|
@@ -189,7 +191,7 @@ LoadError: cannot load such file -- pry
|
|
189
191
|
from (irb):1:in `require'
|
190
192
|
from (irb):1
|
191
193
|
from bin/console:10:in `<main>'
|
192
|
-
>> DuckPuncher.
|
194
|
+
>> DuckPuncher.(Object, only: :require!)
|
193
195
|
=> nil
|
194
196
|
>> require! 'pry'
|
195
197
|
Fetching: method_source-0.8.2.gem (100%)
|
@@ -209,7 +211,7 @@ if it's not available in the current load path, and starts tracking the current
|
|
209
211
|
```ruby
|
210
212
|
Duck = Class.new
|
211
213
|
Donald = Module.new { def tap_tap() self end }
|
212
|
-
DuckPuncher.
|
214
|
+
DuckPuncher.(:Object, only: :track)
|
213
215
|
Donald.track
|
214
216
|
Duck.track
|
215
217
|
>> Duck.usable Donald, only: :tap_tap
|
@@ -1,5 +1,5 @@
|
|
1
1
|
DuckPuncher.logger = Logger.new(STDOUT).tap do |config|
|
2
|
-
config.formatter = proc { |*args| "[
|
2
|
+
config.formatter = proc { |*args| "[DuckPuncher] #{args[0]}: #{args[-1]}\n" }
|
3
3
|
config.level = Logger::ERROR
|
4
4
|
end
|
5
5
|
|
@@ -7,7 +7,6 @@ ducks = [
|
|
7
7
|
[String, DuckPuncher::Ducks::String],
|
8
8
|
[Enumerable, DuckPuncher::Ducks::Enumerable],
|
9
9
|
[Array, DuckPuncher::Ducks::Enumerable],
|
10
|
-
[Hash, DuckPuncher::Ducks::Enumerable],
|
11
10
|
[Numeric, DuckPuncher::Ducks::Numeric],
|
12
11
|
[Hash, DuckPuncher::Ducks::Hash],
|
13
12
|
[Object, DuckPuncher::Ducks::Object],
|
data/lib/duck_puncher/version.rb
CHANGED