tapenade 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc7843737d6d443a6276b7013ebb24eded11117b65de32f17e44f1e7690d6d2a
4
- data.tar.gz: 78fead655d7f22f6c80c958c9677a1445285e41e71d8315d0d97057faa5dcd3b
3
+ metadata.gz: 27a619de5b576a268b65c1abd55af9c9296b2c0b2fa88e2759f0f61b265cabd4
4
+ data.tar.gz: 524e491e466cdf607abcee4c41f270fa0da7dd2e869bf663b31ebcddad7a69ce
5
5
  SHA512:
6
- metadata.gz: 0d610830cf9daa8fca5fa22bdf6c6a71b982664d99642e67cc8332c912d39f813becb874e958d596d8f00a6622d7934aa10363c5e560a4cb187d6261815636aa
7
- data.tar.gz: 22d739b5e59e9f6f0991f34dae36c88f3a214975c72ea5a6380b25b98b746cc5006c77053b950a5d3ac4a2c69a8a54cd8ea96e9b595e1f2cdeb2c545b7dfeb67
6
+ metadata.gz: 3933c8a404c457397648bbdb6ce0574415b6d9ba811011eedcce998b45181f718accc3a08aec714ebdb513dc0b21a3f83f77c348bdcab5e1490fd67029fc2484
7
+ data.tar.gz: d3fc7f6252a072563ecaf0968661a392958a7d8420e2a99c794c8c99cdbe96467ebf8ab7547e2cd672f9fd176a6df1f51fee98cae3deedf0d600880b2d06b605
data/README.md CHANGED
@@ -1,30 +1,23 @@
1
1
  # Tapenade
2
2
 
3
- Want to call a method and return `self` instead of normal return ? Just prefix it with `tap_` !
3
+ Tapenade allows to chain method after `tap` instead of using a block.
4
4
 
5
5
  ## Examples
6
6
 
7
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
8
  # With Ruby's tap
16
- def update_user
17
- User.find(param[:id]).tap { |user| user.update!(user_params) }
18
- end
9
+ User.find(param[:id]).tap { |user| user.update!(user_params) }
10
+ # => returns the user
19
11
 
20
12
  # With Tapenade:
21
- def update_user
22
- User.find(param[:id]).tap_update!(user_params)
23
- end
13
+ User.find(param[:id]).tap.update!(user_params)
14
+ # => returns the user
24
15
  ```
25
16
 
26
17
  Examples are using Rails models but it works with any method on any object.
27
18
 
19
+ You can of course still use `tap` with blocks as usual.
20
+
28
21
  ## Installation
29
22
 
30
23
  Add this line to your application's Gemfile:
@@ -33,6 +26,8 @@ Add this line to your application's Gemfile:
33
26
  gem "tapenade"
34
27
  ```
35
28
 
29
+ That's all.
30
+
36
31
  ## License
37
32
 
38
33
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "delegate"
2
+
3
+ module Tapenade
4
+ class Delegator < SimpleDelegator
5
+ def method_missing(...)
6
+ super
7
+ __getobj__
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ module Tapenade
2
+ module Tap
3
+ def tap
4
+ return super if block_given?
5
+ Tapenade::Delegator.new(self)
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Tapenade
2
- VERSION = "0.3.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/tapenade.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "tapenade/version"
2
- require "tapenade/module"
2
+ require "tapenade/delegator"
3
+ require "tapenade/tap"
3
4
 
4
- Object.send(:include, Tapenade)
5
+ Object.include(Tapenade::Tap)
metadata CHANGED
@@ -1,19 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tapenade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benoit MARTIN-CHAVE
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-26 00:00:00.000000000 Z
11
+ date: 2022-11-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Want to call a method and return self instead of normal return ? Just
14
- prefix it with tap_ !
13
+ description: Improved tap method
15
14
  email:
16
- - benoit@martin-chave.ch
15
+ - benoit@martin-chave.com
17
16
  executables: []
18
17
  extensions: []
19
18
  extra_rdoc_files: []
@@ -21,13 +20,14 @@ files:
21
20
  - LICENSE.txt
22
21
  - README.md
23
22
  - lib/tapenade.rb
24
- - lib/tapenade/module.rb
23
+ - lib/tapenade/delegator.rb
24
+ - lib/tapenade/tap.rb
25
25
  - lib/tapenade/version.rb
26
26
  homepage: https://github.com/benoitmc/tapenade
27
27
  licenses:
28
28
  - MIT
29
29
  metadata: {}
30
- post_install_message:
30
+ post_install_message:
31
31
  rdoc_options: []
32
32
  require_paths:
33
33
  - lib
@@ -35,16 +35,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
35
35
  requirements:
36
36
  - - ">="
37
37
  - !ruby/object:Gem::Version
38
- version: '0'
38
+ version: 2.7.0
39
39
  required_rubygems_version: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
44
  requirements: []
45
- rubygems_version: 3.1.2
46
- signing_key:
45
+ rubygems_version: 3.3.7
46
+ signing_key:
47
47
  specification_version: 4
48
- summary: Want to call a method and return self instead of normal return ? Just prefix
49
- it with tap_ !
48
+ summary: Improved tap method
50
49
  test_files: []
@@ -1,22 +0,0 @@
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, **kwargs, &block)
13
- return super unless respond_to_tapenade?(method)
14
- # Ruby 2.6 + 2.7 friendly
15
- eval "#{method.to_s[Tapenade.prefix.length..-1]}(*args, **kwargs, &block)"
16
- self
17
- end
18
-
19
- def respond_to_tapenade?(method)
20
- method.to_s.start_with?(Tapenade.prefix) && respond_to?(method.to_s[Tapenade.prefix.length..-1])
21
- end
22
- end