tapenade 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/lib/tapenade/module.rb +21 -0
- data/lib/tapenade/version.rb +3 -0
- data/lib/tapenade.rb +4 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fde587b9217fccfa5abeedad13d0b2a93910070075e79bbd414c2663b413970f
|
4
|
+
data.tar.gz: 566961bece3368d19d4d5f0065cb08f88ed88a194e30c0652a21691e9f632b55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51bd427adfd5dc36f5c58dfa527a880ac36c944435498e165b881efbd199f9d4149e6111a90195ea4a89efa6d11b7e249a92bb38c03015fd6dbd4bb530306e0f
|
7
|
+
data.tar.gz: 5b594b12f91f06e3ed571ea0fc63d0333e9f7dfe6fccee5453f5773f9cff0a73eeeb81e33dd6c62cc0d00c200e150d0a65a260287961fe5993197947d8012a75
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Benoit MARTIN-CHAVE
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Tapenade
|
2
|
+
|
3
|
+
Want to call a method and return `self` instead of normal return ? Just prefix it with `tap_` !
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Without any tap method:
|
9
|
+
def update_user
|
10
|
+
user = User.find(param[:id])
|
11
|
+
user.update!(user_params)
|
12
|
+
return user
|
13
|
+
end
|
14
|
+
|
15
|
+
# With Ruby's tap
|
16
|
+
def update_user
|
17
|
+
User.find(param[:id]).tap { |user| user.update!(user_params) }
|
18
|
+
end
|
19
|
+
|
20
|
+
# With Tapenade:
|
21
|
+
def update_user
|
22
|
+
User.find(param[:id]).tap_update!(user_params)
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
Examples are using Rails models but it works with any method on any object.
|
27
|
+
|
28
|
+
## Installation
|
29
|
+
|
30
|
+
Add this line to your application's Gemfile:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
gem "tapenade"
|
34
|
+
```
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Tapenade
|
2
|
+
def self.prefix
|
3
|
+
"tap_".freeze
|
4
|
+
end
|
5
|
+
|
6
|
+
private
|
7
|
+
|
8
|
+
def respond_to_missing?(method, include_private = false)
|
9
|
+
respond_to_tapenade?(method) || super
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method, *args, &block)
|
13
|
+
return super unless respond_to_tapenade?(method)
|
14
|
+
public_send(method.to_s[Tapenade.prefix.length..-1], *args, &block)
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def respond_to_tapenade?(method)
|
19
|
+
method.to_s.start_with?(Tapenade.prefix) && respond_to?(method.to_s[Tapenade.prefix.length..-1])
|
20
|
+
end
|
21
|
+
end
|
data/lib/tapenade.rb
ADDED
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tapenade
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benoit MARTIN-CHAVE
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Want to call a method and return self instead of normal return ? Just
|
14
|
+
prefix it with tap_ !
|
15
|
+
email:
|
16
|
+
- benoit@martin-chave.ch
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- lib/tapenade.rb
|
24
|
+
- lib/tapenade/module.rb
|
25
|
+
- lib/tapenade/version.rb
|
26
|
+
homepage: https://github.com/benoitmc/tapenade
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
requirements: []
|
45
|
+
rubygems_version: 3.0.3
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Want to call a method and return self instead of normal return ? Just prefix
|
49
|
+
it with tap_ !
|
50
|
+
test_files: []
|